~/bend-docscommunity

main.bend fails

raw source on the hub · import emerging-ezhttp@0.8.0.0/main.bend as Main

ezhttp: HTTP/1.1 client and server for Bend 2, with auth, cookie and CORS helpers.

Shared message types, BYO JSON via encode/decode. TLS for the client stays at the wire/runtime layer.

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

Definitions

def parse_url source · line 16 · raw

@url:String -> 0xf1c957a470368870a6d1d62a8c0cbe32/src/url.Loc

URL parse re-export

def parse_response source · line 20 · raw

@raw:String -> 0xf1c957a470368870a6d1d62a8c0cbe32/src/http.Reply

response parse re-export

def parse_request source · line 24 · raw

@raw:String -> 0xf1c957a470368870a6d1d62a8c0cbe32/src/http.Request

request parse re-export (server inbound)

def format_response source · line 28 · raw

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

format a response message (server outbound)

def empty_body source · line 33 · raw

0xf1c957a470368870a6d1d62a8c0cbe32/src/body.Body

empty request body

def text_body source · line 37 · raw

@s:String -> 0xf1c957a470368870a6d1d62a8c0cbe32/src/body.Body

UTF-8 text request body

def octets_body source · line 41 · raw

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

octet-list request body

def bearer source · line 57 · raw

@token:String -> 0xf1c957a470368870a6d1d62a8c0cbe32/src/http.Header

Bearer token header helper

def basic source · line 61 · raw

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

Basic credentials header (RFC 7617)

def cache_control source · line 77 · raw

@value:String -> 0xf1c957a470368870a6d1d62a8c0cbe32/src/cache.Cc

parse a Cache-Control field value (RFC 9111)

def fresh source · line 81 · raw

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

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

def cors_reply source · line 85 · raw

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

CORS preflight or simple headers on a handler reply

def http.get source · line 89 · raw

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

GET with no extra headers

def http.get_with source · line 93 · raw

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

GET with headers

def http.head source · line 98 · raw

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

HEAD with no extra headers

def http.head_with source · line 102 · raw

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

HEAD with headers

def http.post source · line 107 · raw

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

POST with a body and no extra headers

def http.post_with source · line 111 · raw

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

POST with headers and a body

def http.put source · line 119 · raw

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

PUT with a body and no extra headers

def http.put_with source · line 123 · raw

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

PUT with headers and a body

def http.delete source · line 128 · raw

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

DELETE with a body and no extra headers

def http.delete_with source · line 132 · raw

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

DELETE with headers and a body

def http.options source · line 140 · raw

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

OPTIONS with no extra headers

def http.options_with source · line 144 · raw

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

OPTIONS with headers

Templates

template encode source · line 45 · raw

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

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

template decode source · line 49 · 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 149 · raw

@-handle:(@_:0xf1c957a470368870a6d1d62a8c0cbe32/src/http.Request -> 0xf1c957a470368870a6d1d62a8c0cbe32/src/http.Reply) -> @host:String -> @port:U32 -> @limit:U32 -> IO(Unit)

listen on host:port and serve up to limit connections

template http.serve_once source · line 158 · raw

@-handle:(@_:0xf1c957a470368870a6d1d62a8c0cbe32/src/http.Request -> 0xf1c957a470368870a6d1d62a8c0cbe32/src/http.Reply) -> @host:String -> @port:U32 -> IO(Unit)

listen on host:port, serve one connection, then stop