std.http

Modules

std.http.types

Types

type Method = String

type Failure = 
    | DontProcess
    | Error String

Type used by handlers to indicate why they could not process a request

type Request = { method : String, uri : Uri, body : Body }

type StatusCode = Int

type Response = { status : Int, headers : Array (String, Array Byte) }

type HttpEffect r a = [|
        alt : std.effect.alt.Alt,
        state : std.effect.state.State HttpState,
        lift : std.effect.lift.Lift IO
        | r
    |]
        a

Values

let alternative : forall r .
    std.alternative.Alternative (std.effect.Eff (std.http.types.HttpEffect r))

A monoid on applicative functors.

let status : {
    ok : StatusCode,
    moved_permanently : Int,
    found : Int,
    temporary_redirect : Int,
    permanent_redirect : Int,
    bad_request : StatusCode,
    not_found : StatusCode,
    internal_server_error : StatusCode
}

let method : { get : Method, post : Method, put : Method }

let empty_response : { status : StatusCode }

Returns OK with an empty body

let get_request : forall r . std.effect.Eff (std.http.types.HttpEffect r) Request

Retrieves the HTTP request

let handle handler state : forall r .
    std.effect.Eff (std.http.types.HttpEffect r) Response
        -> HttpState
        -> IO Response

Takes a Handler and a Request tries to process the request

let get : forall r . std.effect.Eff (std.http.types.HttpEffect r) ()

Handles Get requests

let post : forall r . std.effect.Eff (std.http.types.HttpEffect r) ()

Handles Post requests

let path p : forall r . String -> std.effect.Eff (std.http.types.HttpEffect r) ()

Processes this handler if uri matches the request's uri

let is_match uri : forall r . String -> std.effect.Eff (std.http.types.HttpEffect r) ()

let io_handler action : forall r a . IO a -> std.effect.Eff (std.http.types.HttpEffect r) a

Converts an IO into a Handler

let fail msg : forall a r . String -> std.effect.Eff (std.http.types.HttpEffect r) a

Throws an exception which aborts the current handler. Can be caught with catch_error

let catch_error action catch : forall a r .
    std.effect.Eff (std.http.types.HttpEffect r) a
        -> (String -> std.effect.Eff (std.http.types.HttpEffect r) a)
        -> std.effect.Eff (std.http.types.HttpEffect r) a

Recovers from an exception thrown by fail

let show_uri : std.show.Show Uri

Show a represents a conversion function from a to a readable string.

let default_listen_settings : { port : Int, tls_cert : forall a . std.types.Option a }

let response : Response

let listen : forall r .
    { port : Int, tls_cert : std.types.Option String }
        -> std.effect.Eff
            (std.http.types.HttpEffect r)
            { status : Int, headers : Array (String, Array Byte) }
        -> IO ()

let read_chunk : Body -> IO (std.types.Option (Array Byte))

let write_response bytes : forall r . Array Byte -> std.effect.Eff (std.http.types.HttpEffect r) ()

Write bytes to the http response

let port : Uri -> std.types.Option Int

let uri : {
    path : Uri -> String,
    host : Uri -> std.types.Option String,
    query : Uri -> std.types.Option String,
    to_string : Uri -> String
}