Reason Native Web
  • Guides
  • Help
  • GitHub
Response (morph.Morph.Response)
Up – morph » Morph » Response

Module Morph.Response

Defines the response type and helper functions to easily create responses in Morph.

type headers = list((string, string));

headers is represented as a list of (string, string) tuples.

type body = [
| `String(string)

Use a simple string as body

| `Stream(Lwt_stream.t(char))

Use a stream of chars as body

| `StringStream(Lwt_stream.t(string))

Use a stream of strings as body

];

Response.body variant type structure. There are currently 3 types of bodies.

`String Use a simple string as body

`Stream Use a stream of chars as body, the stream will be written fully before flushing

`StringStream Use a stream of strings as body, it will be flushed on every new string

type t = {
status: Status.t,
headers: headers,
body: body,
};

The core Response.t type

let make: ?⁠status:Status.t => ?⁠headers:headers => body => t;

make status headers body creates a response.

let empty: t;

empty t an empty response, a starting place to compose an http response.

let add_header: (string, string) => t => t;

add_header header response returns a copy of t of response with the header tuple added.

let add_headers: headers => t => t;

add_header headers response returns a copy of t of response with the headers added.

let set_status: Status.t => t => t;

set_status status response returns a copy of t with the given status.

let set_body: body => t => t;

set_body body response returns a copy of t with the given body.

let ok: t => Lwt.t(t);

ok response is a conventience function to return a 200 OK response.

let text: string => t => Lwt.t(t);

text text response is a conventience function to return a text response.

let json: string => t => Lwt.t(t);

json json response is a conventience function to return a JSON response.

let html: string => t => Lwt.t(t);

html markup response is a conventience function to return a HTML response.

let redirect: ?⁠code:int => string => t => Lwt.t(t);

redirect code target response is a conventience function to create a redirect response.

let unauthorized: string => t => Lwt.t(t);

unauthorized message response is a conventience function to return a unauthorized response.

let not_found: ?⁠message:string => t => Lwt.t(t);

not_found message response is a conventience function to return a 404 Not found response.

let static: string => t => Lwt.t(t);

static file_path response is a convenience function to return a 200 response with the contents of a static file. If the file does not exist a 404 Not found response is sent instead.

Reason Native Web
Docs
Your first web serverGuidesAPI Reference
Community
Reason DiscordReasonML ForumOCaml DiscordOCaml Discuss
More
GitHub
Copyright © 2019 Your Name or Your Company Name