Documentation

Hale.Req.Network.HTTP.Req

URL scheme, used as a phantom parameter on Url and Option to enforce HTTPS-only constraints at the type level. $$\text{Scheme} = \text{Http} \mid \text{Https}$$

Instances For
    @[implicit_reducible]
    Equations
    Equations
    • One or more equations did not get rendered due to their size.
    Instances For

      HTTP and HTTPS schemes are distinct (enables auth separation).

      structure Network.HTTP.Req.Url (scheme : Scheme) :

      A correct-by-construction URL parameterized by scheme.

      The scheme phantom parameter enables HTTPS-only auth enforcement. Hostname is proven non-empty by construction. Path segments are stored in order.

      $$\text{Url}\ s = \{ \text{host} : \{h : \text{String} \mid h.\text{length} > 0\},\; \text{segments} : \text{List String} \}$$

      • host : String

        The hostname. Must be non-empty (enforced by proof).

      • segments : List String

        Path segments (e.g., ["api", "v1", "users"]).

      • host_nonempty : self.host.length > 0

        Host is non-empty (proof, erased at runtime).

      Instances For
        @[implicit_reducible]
        Equations
        • One or more equations did not get rendered due to their size.
        def Network.HTTP.Req.http (host : String) (h : host.length > 0 := by decide) :

        Construct an HTTP URL from a hostname. $$\text{http} : \text{String} \to \text{Url .Http}$$

        Equations
        Instances For
          def Network.HTTP.Req.https (host : String) (h : host.length > 0 := by decide) :

          Construct an HTTPS URL from a hostname. $$\text{https} : \text{String} \to \text{Url .Https}$$

          Equations
          Instances For
            def Network.HTTP.Req.Url.append {s : Scheme} (url : Url s) (segment : String) :
            Url s

            Append a path segment to a URL. $$(\text{/:}) : \text{Url}\ s \to \text{String} \to \text{Url}\ s$$

            Equations
            Instances For

              Infix operator for path segments: https "api.example.com" /: "v1" /: "users"

              Equations
              • One or more equations did not get rendered due to their size.
              Instances For

                Render a URL's path component (with leading /).

                Equations
                Instances For

                  Get the default port for a URL based on its scheme.

                  Equations
                  Instances For

                    Whether the URL scheme is secure (HTTPS).

                    Equations
                    Instances For

                      Whether an HTTP method allows a request body. $$\text{CanHaveBody} = \text{YesBody} \mid \text{NoBody}$$

                      Instances For
                        Equations
                        • One or more equations did not get rendered due to their size.
                        Instances For

                          Typeclass for HTTP methods. Maps each method to its body permission and wire name. $$\text{HttpMethod}\ m = \{ \text{allowsBody} : \text{CanHaveBody},\; \text{methodName} : \text{String} \}$$

                          • allowsBody : CanHaveBody

                            Whether this method allows a request body.

                          • methodName : String

                            The HTTP method name as it appears on the wire (e.g., "GET").

                          Instances

                            Typeclass for HTTP request bodies. Maps each body type to its content and content-type. $$\text{HttpBody}\ b = \{ \text{providesBody} : \text{CanHaveBody},\; \text{getBody} : b \to \text{Option ByteArray},\; \text{getContentType} : b \to \text{Option String} \}$$

                            • providesBody : CanHaveBody

                              Whether this body type provides a body.

                            • getBody : bOption ByteArray

                              Get the body bytes. none means no body.

                            • getContentType : bOption String

                              Get the Content-Type header value.

                            Instances

                              Compile-time constraint: method/body compatibility.

                              This typeclass has instances for all valid combinations:

                              • (.YesBody, .YesBody) — POST with body
                              • (.YesBody, .NoBody) — POST with no body (allowed)
                              • (.NoBody, .NoBody) — GET with no body

                              The missing instance (.NoBody, .YesBody) means that req GET url (ReqBodyBs data) ... fails at compile time with "failed to synthesize HttpBodyAllowed .NoBody .YesBody".

                                Instances

                                  HTTP GET method. Does not allow a request body.

                                    Instances For

                                      HTTP POST method. Allows a request body.

                                        Instances For

                                          HTTP HEAD method. Does not allow a request body.

                                            Instances For

                                              HTTP PUT method. Allows a request body.

                                                Instances For

                                                  HTTP DELETE method. Does not allow a request body (matches Haskell req).

                                                    Instances For

                                                      HTTP PATCH method. Allows a request body.

                                                        Instances For

                                                          HTTP OPTIONS method. Does not allow a request body.

                                                            Instances For

                                                              HTTP TRACE method. Does not allow a request body.

                                                                Instances For

                                                                  HTTP CONNECT method. Does not allow a request body.

                                                                    Instances For

                                                                      No request body. Used with GET, HEAD, DELETE, etc.

                                                                        Instances For

                                                                          Strict ByteArray body. Sets Content-Type to application/octet-stream.

                                                                          Instances For
                                                                            @[implicit_reducible]
                                                                            Equations
                                                                            • One or more equations did not get rendered due to their size.

                                                                            Lazy ByteArray body (same as strict for now; lazy distinction is for API compatibility).

                                                                            Instances For
                                                                              @[implicit_reducible]
                                                                              Equations
                                                                              • One or more equations did not get rendered due to their size.

                                                                              URL-encoded form body (application/x-www-form-urlencoded).

                                                                              Instances For
                                                                                @[implicit_reducible]
                                                                                Equations
                                                                                • One or more equations did not get rendered due to their size.

                                                                                File body. Reads the file at send time.

                                                                                Instances For
                                                                                  @[implicit_reducible]
                                                                                  Equations
                                                                                  • One or more equations did not get rendered due to their size.

                                                                                  Typeclass for HTTP response interpretation. Defines how to parse the raw Network.HTTP.Client.Response into a typed response value. $$\text{HttpResponse}\ r = \{ \text{interpretResponse} : \text{Response} \to \text{IO}\ r,\; \text{acceptHeader} : \text{Option String} \}$$

                                                                                  • interpretResponse : Client.ResponseIO r

                                                                                    Parse a raw HTTP response into the typed response.

                                                                                  • acceptHeader : Option String

                                                                                    Optional Accept header value to send with the request.

                                                                                  Instances

                                                                                    Ignore the response body. Only status and headers are returned.

                                                                                    Instances For
                                                                                      Equations
                                                                                      • One or more equations did not get rendered due to their size.
                                                                                      Instances For
                                                                                        @[implicit_reducible]
                                                                                        Equations

                                                                                        Strict ByteArray response — returns the full body as a ByteArray.

                                                                                        Instances For
                                                                                          @[implicit_reducible]
                                                                                          Equations
                                                                                          • One or more equations did not get rendered due to their size.

                                                                                          Select BsResponse as the response type.

                                                                                          Equations
                                                                                          Instances For
                                                                                            structure Network.HTTP.Req.ReqOption (scheme : Scheme) :

                                                                                            Composable request options, parameterized by scheme.

                                                                                            Forms a Monoid via Append / EmptyCollection. The scheme phantom parameter enables HTTPS-only authentication enforcement: basicAuth returns ReqOption .Https, so it can only be passed to req when the URL is also Url .Https.

                                                                                            $$\text{ReqOption}\ s = \{ \text{extraHeaders},\; \text{queryParams},\; \text{portOverride},\; \text{timeout} \}$$

                                                                                            Instances For
                                                                                              Equations
                                                                                              • One or more equations did not get rendered due to their size.
                                                                                              Instances For
                                                                                                @[implicit_reducible]
                                                                                                Equations
                                                                                                • One or more equations did not get rendered due to their size.

                                                                                                ReqOption append is associative for the list-based fields.

                                                                                                Add a custom header to the request.

                                                                                                Equations
                                                                                                Instances For

                                                                                                  Override the port.

                                                                                                  Equations
                                                                                                  Instances For

                                                                                                    Add a query parameter.

                                                                                                    Equations
                                                                                                    Instances For

                                                                                                      Add a boolean query flag (parameter with no value).

                                                                                                      Equations
                                                                                                      Instances For

                                                                                                        Set the response timeout in milliseconds.

                                                                                                        Equations
                                                                                                        Instances For

                                                                                                          Basic authentication. HTTPS-only enforced by the return type ReqOption .Https.

                                                                                                          Using this with an http URL is a compile-time error: the type ReqOption .Https does not unify with ReqOption .Http.

                                                                                                          $$\text{basicAuth} : \text{String} \to \text{String} \to \text{ReqOption .Https}$$

                                                                                                          Equations
                                                                                                          • One or more equations did not get rendered due to their size.
                                                                                                          Instances For

                                                                                                            OAuth 2.0 bearer token. HTTPS-only. $$\text{oAuth2Bearer} : \text{String} \to \text{ReqOption .Https}$$

                                                                                                            Equations
                                                                                                            Instances For

                                                                                                              OAuth 2.0 token (alternative form). HTTPS-only.

                                                                                                              Equations
                                                                                                              Instances For

                                                                                                                Unsafe basic auth that works over any scheme. The caller is responsible for transport security.

                                                                                                                Equations
                                                                                                                • One or more equations did not get rendered due to their size.
                                                                                                                Instances For

                                                                                                                  HTTP client configuration.

                                                                                                                  Controls redirect following, timeouts, and response validation. The redirectCount_le proof prevents unbounded redirect following.

                                                                                                                  $$\text{HttpConfig} = \{ \text{redirectCount} : \{n : \mathbb{N} \mid n \leq 100\},\; \text{timeout},\; \text{checkResponse} \}$$

                                                                                                                  • httpConfigRedirectCount : Nat

                                                                                                                    Maximum number of redirects to follow.

                                                                                                                  • httpConfigTimeout : Nat

                                                                                                                    Default response timeout in milliseconds. 0 = no timeout.

                                                                                                                  • httpConfigCheckResponse : Types.StatusOption String

                                                                                                                    Custom response validation. Return some errorMsg to throw on non-2xx.

                                                                                                                  • redirectCount_le : self.httpConfigRedirectCount 100

                                                                                                                    Redirect count is bounded (prevents unbounded recursion).

                                                                                                                  Instances For

                                                                                                                    Default HTTP config with sensible defaults.

                                                                                                                    Equations
                                                                                                                    Instances For
                                                                                                                      structure Network.HTTP.Req.Req (α : Type) :

                                                                                                                      The Req monad: IO with HTTP configuration via ReaderT pattern. $$\text{Req}\ \alpha = \text{HttpConfig} \to \text{IO}\ \alpha$$

                                                                                                                      • run : HttpConfigIO α

                                                                                                                        The underlying computation, a function from config to IO.

                                                                                                                      Instances For
                                                                                                                        @[implicit_reducible]
                                                                                                                        Equations
                                                                                                                        @[implicit_reducible]
                                                                                                                        Equations
                                                                                                                        @[implicit_reducible]
                                                                                                                        Equations
                                                                                                                        • One or more equations did not get rendered due to their size.
                                                                                                                        @[implicit_reducible]
                                                                                                                        Equations
                                                                                                                        • One or more equations did not get rendered due to their size.
                                                                                                                        @[implicit_reducible]
                                                                                                                        Equations
                                                                                                                        class Network.HTTP.Req.MonadHttp (m : TypeType) extends Monad m :

                                                                                                                        The MonadHttp typeclass. Any monad that can perform HTTP requests.

                                                                                                                        • map {α β : Type} : (αβ)m αm β
                                                                                                                        • mapConst {α β : Type} : αm βm α
                                                                                                                        • pure {α : Type} : αm α
                                                                                                                        • seq {α β : Type} : m (αβ)(Unitm α)m β
                                                                                                                        • seqLeft {α β : Type} : m α(Unitm β)m α
                                                                                                                        • seqRight {α β : Type} : m α(Unitm β)m β
                                                                                                                        • bind {α β : Type} : m α(αm β)m β
                                                                                                                        • getHttpConfig : m HttpConfig

                                                                                                                          Get the current HTTP configuration.

                                                                                                                        • handleHttpException {α : Type} : IO.Errorm α

                                                                                                                          Handle an HTTP exception.

                                                                                                                        • liftIO {α : Type} : IO αm α

                                                                                                                          Lift an IO action into the monad.

                                                                                                                        Instances
                                                                                                                          @[implicit_reducible]
                                                                                                                          Equations
                                                                                                                          • One or more equations did not get rendered due to their size.
                                                                                                                          def Network.HTTP.Req.runReq {α : Type} (config : HttpConfig := defaultHttpConfig) (action : Req α) :
                                                                                                                          IO α

                                                                                                                          Run a Req computation with the given configuration. $$\text{runReq} : \text{HttpConfig} \to \text{Req}\ \alpha \to \text{IO}\ \alpha$$

                                                                                                                          Equations
                                                                                                                          Instances For
                                                                                                                            def Network.HTTP.Req.req {methodTy bodyTy response : Type} {scheme : Scheme} [HttpMethod methodTy] [HttpBody bodyTy] [HttpResponse response] [HttpBodyAllowed (HttpMethod.allowsBody methodTy) (HttpBody.providesBody bodyTy)] (m : methodTy) (url : Url scheme) (b : bodyTy) (_responseHint : response) (options : ReqOption scheme := ) :
                                                                                                                            Req response

                                                                                                                            Make a type-safe HTTP request.

                                                                                                                            This is the central function of the library. Type parameters enforce correctness at compile time:

                                                                                                                            $$\text{req} : m \to \text{Url}\ s \to b \to r \to \text{ReqOption}\ s \to \text{Req}\ r$$

                                                                                                                            Equations
                                                                                                                            • One or more equations did not get rendered due to their size.
                                                                                                                            Instances For

                                                                                                                              Get the response body from a BsResponse.

                                                                                                                              Equations
                                                                                                                              Instances For

                                                                                                                                Get the response status from a BsResponse.

                                                                                                                                Equations
                                                                                                                                Instances For

                                                                                                                                  Look up a header value in the response (case-insensitive).

                                                                                                                                  Equations
                                                                                                                                  Instances For

                                                                                                                                    Get the response status from an IgnoreResponse.

                                                                                                                                    Equations
                                                                                                                                    Instances For

                                                                                                                                      Look up a header value in an IgnoreResponse.

                                                                                                                                      Equations
                                                                                                                                      Instances For