Skip to Content
i documentation
Standard library referenceModules

std/http

HTTP/1.1 messages, incremental framing, clients and scoped servers.

Client

Client = (

Transport

Transport = (

ResponseStream

ResponseStream = { (

native_client

native_client = () <- (n : net.Net, t : tls.Tls) {

fetch_client

fetch_client = () <- (f : fetch.Fetch) {

send_stream

send_stream = (req : Request) -> ResponseStream {

Method

Method = (String)

Status

Status = (Int)

Headers

Headers = (List((String, String)))

RawHeaders

RawHeaders = (List((String, BitArray)))

AnyHeaders

Before stage 3 this sum was Headers, with a constructor of that name; a member is now a type of its own (syntax-3.md §2.8, §7.3 manual list), so the sum is AnyHeaders.

AnyHeaders = Headers | RawHeaders

Request

Request = (

Response

Response = (

HttpError

HttpError = NeedMore

Progress

Progress(A) = More | Complete(A) | Invalid

request

request = (method : Method, target : String) -> Request {

response

response = (status : Status) -> Response {

feed_request

feed_request = (buffer : BitArray, bytes : BitArray) -> Progress(Request) {

feed_response

feed_response = (buffer : BitArray, bytes : BitArray) -> Progress(Response) {

feed_response_for

Parse a response with its request method and whether the connection ended.

feed_response_for = (

feed_request_limit

feed_request_limit = (
header = (hs : AnyHeaders, name : String) -> Option(String) {

header_bytes

header_bytes = (hs : AnyHeaders, name : String) -> Option(BitArray) {

headers

headers = (hs : AnyHeaders, name : String) -> List(String) {

add_header

add_header = (hs : AnyHeaders, name : String, value : String) -> AnyHeaders {

serialize_request

serialize_request = (req : Request) -> BitArray {

serialize_response

serialize_response = (res : Response) -> BitArray {

reason

reason = (status : Int) -> String {

parse_query

parse_query = (query : String) -> Result(

build_query

build_query = (pairs : List((String, String))) -> String {

serve

Buffered request handler, built on the incremental body reader.

serve = (listener, handler) {

serve_stream

Serve a head and a pull reader; the reader is valid until the handler returns.

serve_stream = (listener, handler) {

get

get = (url : String) -> Response { send(request(Method("GET"), url)) }

post

post = (url : String, body : BitArray) -> Response {

send

send = (req : Request) -> Response {

client

client = () <- (c : Client) -> ClientFunctions {

body_text

body_text = (res : Response) { bit_array.to_string(res.body) }

body_json

body_json = (res : Response) -> Result(json.Json, BodyError) {

body_decode

body_decode = <A>(

BodyError

BodyError = InvalidText | InvalidJson | InvalidSchema

send_with

Send with a provider’s send function, as client().send; a caller may give any function of this type in its place.

send_with = <N>(send : (Request) <- N -> Response, req : Request) -> Response {

send_timeout

send_with, failing with Timeout when no response comes in time.

send_timeout = <N>(

route

Match a method and slash-separated path; segments prefixed with ‘:’ bind parameters.

route = (method : Method, pattern : String, req : Request) -> Option(

content_length

content_length = "Content-Length"

content_type

content_type = "Content-Type"

transfer_encoding

transfer_encoding = "Transfer-Encoding"

host

host = "Host"

connection

connection = "Connection"