Module Webs.Http_client

HTTP clients.

See the quick start and the cookbock.

Clients

val default_max_redirection : int

default_max_redirection is 10, the default maximal number of redirections when they are followed, see request.

type t

The type for HTTP clients.

val id : t -> string

id httpc identifies the underlying implementation of httpc.

val request : ?max_redirections:int -> t -> follow:bool -> Http.Request.t -> (Http.Response.t, string) Stdlib.result

request httpc ~follow request performs request request via httpc. To construct a request from an URL use Http.Request.of_url. Read more details about how request is interpreted by client connectors in the client connector conventions.

If follow is true and the request is GET or HEAD, HTTP responses are automatically redirected on 301, 302, 303, 305, 307 and 308. In this case the the original request is modified as follows:

The maximal number of redirection is given by max_redirection and defaults to default_max_redirection.

If, and only if, there was a follow, the final requested URL can be found in the response in the x_follow_location header.

val get : t -> follow:bool -> url:Url.t -> (string, string) Stdlib.result

get c ~follow ~url is the body of a successful GET request on url. For the semantics of follow see request.

Note. This is voluntarily kept bare bones (e.g. no headers can be specified). Anything more complex should use request.

val x_follow_location : Http.Headers.Name.t

x_follow_location is the final location that was requested on ~follow:true. Only added if there was a redirection.

Client connectors

If you devise your own HTTP client it should provide constructor functions that return Http_client.t values directly. These values are constructed with make.

module type T = sig ... end

Client connector.

val make : (module T with type t = 'a) -> 'a -> t

make impl httpc packs an HTTP client implementation impl and its specific implementation httpc.