package b0

  1. Overview
  2. Docs

HTTP requests.

HTTP requests via curl.

HTTP methods and headers

type meth = [
  1. | `CONNECT
  2. | `DELETE
  3. | `GET
  4. | `HEAD
  5. | `OPTIONS
  6. | `Other of string
  7. | `PATCH
  8. | `POST
  9. | `PUT
  10. | `TRACE
]

The type for HTTP methods.

val meth_to_string : meth -> string

meth_to_string m is a string representation of m.

type headers = (string * string) list

The type for HTTP headers.

HTTP requests

type req

The type for HTTP requests.

val req : ?headers:headers -> ?body:string -> uri:string -> meth -> req

req uri m ~headers ~body is a request on uri with method m, headers headers (defaults to []) and body body (defaults to "").

val req_uri : req -> string

req_uri r is r's request URI.

val req_meth : req -> meth

req_meth r is r's HTTP method.

val req_headers : req -> headers

req_headers r is r's headers.

val req_body : req -> string

req_body r is r's body.

HTTP responses

type resp

The type for HTTP responses.

val resp_headers : resp -> headers

resp_headers r are the HTTP response headers.

val resp_status : resp -> int

resp_status r is the HTTP response status.

val resp_body : resp -> string

resp_body r is the HTTP response body.

Performing requests

type t

The type for HTTP requestors.

val curl : ?docs:string -> ?env:Cmdliner.Arg.env -> unit -> B0_std.Cmd.t Cmdliner.Term.t

curl is a cli interface for specifying the curl command line tool.

val find_curl : ?search:B0_std.Fpath.t list -> curl:B0_std.Cmd.t -> unit -> (t, string) result
val perform : ?follow:bool -> t -> req -> (resp, string) result

perform curl r performs request r via curl which is looked up in the PATH or in the environment variable B0_CURL. If follow is true (default) HTTP redirects for GET and HEAD requests that return 301, 302, 303, 305 or 307 are automatically followed.

OCaml

Innovation. Community. Security.