~/bend-docscommunity

main.bend fails

raw source on the hub · import 0x0a372da4a053652f70ded7d6e0d19330/main.bend as Main

ezhttp: HTTP client and server for Bend 2. Shared message types, BYO JSON via encode/decode. TLS for the client stays at the wire/runtime layer.

9 imports
import Base
import ./url.bend as Url
import ./http.bend as Http
import ./body.bend as Body
import ./client.bend as Client
import ./server.bend as Server
import ./cookie.bend as Cookie
import ./cache.bend as Cache
import ./cors.bend as Cors

Definitions

def parse_url source · line 14 · raw

@url:String -> 0x0a372da4a053652f70ded7d6e0d19330/url.Loc

URL parse re-export

def parse_response source · line 18 · raw

@raw:String -> 0x0a372da4a053652f70ded7d6e0d19330/http.Reply

response parse re-export

def parse_request source · line 22 · raw

@raw:String -> 0x0a372da4a053652f70ded7d6e0d19330/http.Request

request parse re-export (server inbound)

def format_response source · line 26 · raw

@status:U32 -> @headers:List<&2, 0x0a372da4a053652f70ded7d6e0d19330/http.Header> -> @body:String -> String

format a response message (server outbound)

def empty_body source · line 31 · raw

0x0a372da4a053652f70ded7d6e0d19330/body.Body

empty request body

def text_body source · line 35 · raw

@s:String -> 0x0a372da4a053652f70ded7d6e0d19330/body.Body

UTF-8 text request body

def octets_body source · line 39 · raw

@bs:List<&2, U32> -> 0x0a372da4a053652f70ded7d6e0d19330/body.Body

octet-list request body

def bearer source · line 55 · raw

@token:String -> 0x0a372da4a053652f70ded7d6e0d19330/http.Header

Bearer token header helper

def basic source · line 59 · raw

@user:String -> @password:String -> 0x0a372da4a053652f70ded7d6e0d19330/http.Header

Basic credentials header (RFC 7617)

def cache_control source · line 75 · raw

@value:String -> 0x0a372da4a053652f70ded7d6e0d19330/cache.Cc

parse a Cache-Control field value (RFC 9111)

def fresh source · line 79 · raw

@value:String -> @age:Nat -> Bool

freshness of a Cache-Control value at an age in seconds

def cors_reply source · line 83 · raw

@cfg:0x0a372da4a053652f70ded7d6e0d19330/cors.Cfg -> @req:0x0a372da4a053652f70ded7d6e0d19330/http.Request -> @reply:0x0a372da4a053652f70ded7d6e0d19330/http.Reply -> 0x0a372da4a053652f70ded7d6e0d19330/http.Reply

CORS preflight or simple headers on a handler reply

def http.get source · line 87 · raw

@url:String -> IO(0x0a372da4a053652f70ded7d6e0d19330/client.Response)

GET with no extra headers

def http.get_with source · line 91 · raw

@url:String -> @headers:List<&2, 0x0a372da4a053652f70ded7d6e0d19330/http.Header> -> IO(0x0a372da4a053652f70ded7d6e0d19330/client.Response)

GET with headers

def http.head source · line 96 · raw

@url:String -> IO(0x0a372da4a053652f70ded7d6e0d19330/client.Response)

HEAD with no extra headers

def http.head_with source · line 100 · raw

@url:String -> @headers:List<&2, 0x0a372da4a053652f70ded7d6e0d19330/http.Header> -> IO(0x0a372da4a053652f70ded7d6e0d19330/client.Response)

HEAD with headers

def http.post source · line 105 · raw

@url:String -> @body:0x0a372da4a053652f70ded7d6e0d19330/body.Body -> IO(0x0a372da4a053652f70ded7d6e0d19330/client.Response)

POST with a body and no extra headers

def http.post_with source · line 109 · raw

@url:String -> @headers:List<&2, 0x0a372da4a053652f70ded7d6e0d19330/http.Header> -> @body:0x0a372da4a053652f70ded7d6e0d19330/body.Body -> IO(0x0a372da4a053652f70ded7d6e0d19330/client.Response)

POST with headers and a body

def http.put source · line 117 · raw

@url:String -> @body:0x0a372da4a053652f70ded7d6e0d19330/body.Body -> IO(0x0a372da4a053652f70ded7d6e0d19330/client.Response)

PUT with a body and no extra headers

def http.put_with source · line 121 · raw

@url:String -> @headers:List<&2, 0x0a372da4a053652f70ded7d6e0d19330/http.Header> -> @body:0x0a372da4a053652f70ded7d6e0d19330/body.Body -> IO(0x0a372da4a053652f70ded7d6e0d19330/client.Response)

PUT with headers and a body

def http.delete source · line 126 · raw

@url:String -> @body:0x0a372da4a053652f70ded7d6e0d19330/body.Body -> IO(0x0a372da4a053652f70ded7d6e0d19330/client.Response)

DELETE with a body and no extra headers

def http.delete_with source · line 130 · raw

@url:String -> @headers:List<&2, 0x0a372da4a053652f70ded7d6e0d19330/http.Header> -> @body:0x0a372da4a053652f70ded7d6e0d19330/body.Body -> IO(0x0a372da4a053652f70ded7d6e0d19330/client.Response)

DELETE with headers and a body

def http.options source · line 138 · raw

@url:String -> IO(0x0a372da4a053652f70ded7d6e0d19330/client.Response)

OPTIONS with no extra headers

def http.options_with source · line 142 · raw

@url:String -> @headers:List<&2, 0x0a372da4a053652f70ded7d6e0d19330/http.Header> -> IO(0x0a372da4a053652f70ded7d6e0d19330/client.Response)

OPTIONS with headers

Templates

template encode source · line 43 · raw

@-A:Data -> @-to_text:(@_:A -> String) -> @value:A -> 0x0a372da4a053652f70ded7d6e0d19330/body.Body

BYO JSON (or any codec): encode a value with the caller's to_text

template decode source · line 47 · raw

@-A:Data -> @-from_text:(@_:String -> Maybe<&2, A>) -> @s:String -> Maybe<&2, A>

BYO JSON (or any codec): decode body text with the caller's from_text

template http.serve source · line 147 · raw

@-handle:(@_:0x0a372da4a053652f70ded7d6e0d19330/http.Request -> 0x0a372da4a053652f70ded7d6e0d19330/http.Reply) -> @port:U32 -> @limit:U32 -> IO(Unit)

listen and serve up to limit connections

template http.serve_once source · line 155 · raw

@-handle:(@_:0x0a372da4a053652f70ded7d6e0d19330/http.Request -> 0x0a372da4a053652f70ded7d6e0d19330/http.Reply) -> @port:U32 -> IO(Unit)

serve one connection then stop