std.http

Modules

std.http.types

A minimal library for writing HTTP servers.

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 : Alt, state : State HttpState, lift : Lift IO | r |] a

Values

#[implicit]
#[implicit]
let alternative : forall r . Alternative (Eff (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 . Eff (HttpEffect r) Request

Retrieves the HTTP request

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

Takes a Handler and a Request tries to process the request

let get : forall r . Eff (HttpEffect r) ()

Handles Get requests

let post : forall r . Eff (HttpEffect r) ()

Handles Post requests

let path p : forall r . String -> Eff (HttpEffect r) ()

Processes this handler if uri matches the request's uri

let is_match uri : forall r . String -> Eff (HttpEffect r) ()

let fail msg : forall a r . String -> Eff (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 .
        Eff (HttpEffect r) a
            -> (String -> Eff (HttpEffect r) a)
            -> Eff (HttpEffect r) a

Recovers from an exception thrown by fail

#[implicit]
let show_uri : Show Uri

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

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

let listen : forall a a0 .
        { port : Int, tls_cert : Option String }
            -> Eff
                (HttpEffect a)
                { status : Int, headers : Array (String, Array Byte) }
            -> Eff [| lift : Lift IO | a0 |] ()

let read_chunk : forall a . Body -> Eff [| lift : Lift IO | a |] (Option (Array Byte))

let write_response bytes : forall r . Array Byte -> Eff (HttpEffect r) ()

Write bytes to the http response

let port : Uri -> Option Int

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