Janet 1.31.0-4e5889e Documentation
(Other Versions: 1.29.1 1.28.0 1.27.0 1.26.0 1.25.1 1.24.0 1.23.0 1.22.0 1.21.0 1.20.0 1.19.0 1.18.1 1.17.1 1.16.1 1.15.0 1.13.1 1.12.2 1.11.1 1.10.1 1.9.1 1.8.1 1.7.0 1.6.0 1.5.1 1.5.0 1.4.0 1.3.1 )

HTTP

Index

http/cookie-grammar http/cookies http/logger http/middleware http/query-string-grammar http/read-body http/read-request http/read-response http/request http/request-peg http/response-peg http/router http/send-response http/server http/server-handler http/status-messages http/url-grammar


http/cookie-grammar core/peg source
Grammar to parse a cookie header to a series of keys and values.
Community Examples

http/cookies function source
(cookies nextmw)

Parses cookies into the table under :cookies key
Community Examples

http/logger function source
(logger nextmw)

Creates a logging middleware. The logger middleware prints URL route, return status, and elapsed request time.
Community Examples

http/middleware function source
(middleware x)

Coerce any type to http middleware
Community Examples

http/query-string-grammar core/peg source
Grammar that parses a query string (sans url path and ? character) and returns a table.
Community Examples

http/read-body function source
(read-body req)

Given a request, read the HTTP body from the connection. Returns the body as a buffer. If the request has no body, returns nil.
Community Examples

http/read-request function source
(read-request conn buf &opt no-query)

Read an HTTP request header from a connection. Returns a table with the following keys: * `:headers` - table mapping header names to header values. Header names are lowercase. * `:connection` - the connection stream for the header. * `:buffer` - the buffer instance that may contain extra bytes. * `:head-size` - the number of bytes used by the header. * `:method` - the HTTP method used. * `:path` - the path of the resource requested. The following keys are also present, but omitted if the user passes a truthy parameter to `no-query`. * `:route` - path of the resource requested without query string. * `:query-string` - segment of HTTP path after first ? character. * `:query` - the query string parsed into a table. Supports a single string value     for every string key, and any query parameters that aren't given a value are mapped to true.  Note that data is read in chunks and any data after the header terminator is  stored in `:buffer.`
Community Examples

http/read-response function source
(read-response conn buf)

Read an HTTP response header from a connection. Returns a table with the following keys: * `:headers` - table mapping header names to header values. Header names are lowercase. * `:connection` - the connection stream for the header. * `:buffer` - the buffer instance that may contain extra bytes. * `:head-size` - the number of bytes used by the header. * `:status` - the HTTP status code. * `:message` - the HTTP status message. Note that data is read in chunks and any data after the header terminator is stored in `:buffer.`
Community Examples

http/request function source
(request method url &keys {:headers headers :body body})

Make an HTTP request to a server. Returns a table containing response information. * `:head-size` - number of bytes in the http header * `:headers` - table mapping header names to header values. Header names are lowercase. * `:connection` - the connection stream for the header. * `:buffer` - the buffer instance that may contain extra bytes. * `:status` - HTTP status code as an integer. * `:message` - HTTP status message. * `:body` - Bytes of the response body.
Community Examples

http/request-peg core/peg source
PEG for parsing HTTP requests
Community Examples

http/response-peg core/peg source
PEG for parsing HTTP responses
Community Examples

http/router function source
(router routes)

Creates a router middleware. A router will dispatch to different routes based on the URL path.
Community Examples

http/send-response function source
(send-response conn response &opt buf)

Send an HTTP response over a connection. Will automatically use chunked encoding if body is not a byte sequence. `response` should be a table with the following keys: * `:headers` - optional headers to write * `:status` - integer status code to write * `:body` - optional byte sequence or iterable (for chunked body) for returning contents. The iterable can be lazy, i.e. for streaming    data.
Community Examples

http/server function source
(server handler &opt host port)

Makes a simple http server. By default it binds to 0.0.0.0:8000, returns a new server stream. Simply wraps http/server-handler with a net/server.
Community Examples

http/server-handler function source
(server-handler conn handler)

A simple connection handler for an HTTP server. When a connection is accepted. Call this with a handler function to handle the connect. The handler will be called with one argument, the request table, which will contain the following keys: * `:head-size` - number of bytes in the http header. * `:headers` - table mapping header names to header values. * `:connection` - the connection stream for the header. * `:buffer` - the buffer instance that may contain extra bytes. * `:path` - HTTP path. * `:method` - HTTP method, as a string.
Community Examples

http/status-messages struct source
Mapping of HTTP status codes to their status message.
Community Examples

http/url-grammar core/peg source
Grammar to parse a URL into domain, port, and path triplet. Only supports the http:// protocol.
Community Examples