~/bend-docscommunity

src/client.bend relies on unsafe/foreign

raw source on the hub · import emerging-ezhttp@0.11.0.0/src/client.bend as Client

ezhttp/src/client: fetch a URL. URL and HTTP parsing joined to the wire effect. Answers a structured Response (status + headers + body), not a hub-style "0\n…" string contract.

8 imports
import Base
import ./url.bend as Url
import ./http.bend as Http
import ./body.bend as Body
import ./wire.bend as Wire
import ./wirespec.bend as Spec
import ./redirect.bend as Redirect
import ./auth.bend as Auth

Types

type Response source · line 14 · raw

Data

structured client result: transport/parse error, or an HTTP response

Definitions

def wire.code source · line 19 · raw

@raw:String -> Maybe<&2, U32>

transport status line: first line is a code, rest is the payload

def wire.text.of source · line 23 · raw

@c:0x86ed7e1c3039a36756163ddcb16e3a95/src/http.Cut -> String

text after the first newline

def wire.text source · line 30 · raw

@raw:String -> String

def wire.ok.of source · line 34 · raw

@m:Maybe<&2, U32> -> Bool

whether the wire status is success (0)

def wire.ok source · line 41 · raw

@raw:String -> Bool

def from.reply source · line 45 · raw

@r:0x86ed7e1c3039a36756163ddcb16e3a95/src/http.Reply -> Response

a torn or successful HTTP parse as a client Response

def from.raw source · line 54 · raw

@+raw:String -> @ok:Bool -> Response

a finished exchange; a failed one keeps its reason, marked when it was a timeout (wirespec.bend wire.why)

def http.talk source · line 62 · raw

@secure:Bool -> @host:String -> @port:U32 -> @req:String -> IO(Response)

HTTP(S) exchange with a pre-built request

def http.loc source · line 69 · raw

@method:String -> @l:0x86ed7e1c3039a36756163ddcb16e3a95/src/url.Loc -> @headers:List<&2, 0x86ed7e1c3039a36756163ddcb16e3a95/src/http.Header> -> @body:String -> IO(Response)

a URL that came apart into an HTTP exchange

def http.talk.timed source · line 79 · raw

@secure:Bool -> @ms:U32 -> @host:String -> @port:U32 -> @req:String -> IO(Response)

HTTP(S) exchange with a pre-built request and a timeout in milliseconds

def http.loc.timed source · line 86 · raw

@ms:U32 -> @l:0x86ed7e1c3039a36756163ddcb16e3a95/src/url.Loc -> @headers:List<&2, 0x86ed7e1c3039a36756163ddcb16e3a95/src/http.Header> -> IO(Response)

a URL that came apart into a GET bounded by a timeout

def client.get.timed source · line 96 · raw

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

GET bounded by a timeout in milliseconds

def client.hop source · line 101 · raw

@left:Nat -> @url:String -> @r:Response -> 0x86ed7e1c3039a36756163ddcb16e3a95/src/redirect.Hop

the next hop after a response (redirect.bend); a failed exchange stops

def client.after source · line 109 · raw

@hop:0x86ed7e1c3039a36756163ddcb16e3a95/src/redirect.Hop -> @r:Response -> @go:(@_:String -> IO(Response)) -> IO(Response)

a response, or the GET its hop asks for

def client.follow source · line 120 · raw

@+left:Nat -> @+url:String -> @+headers:List<&2, 0x86ed7e1c3039a36756163ddcb16e3a95/src/http.Header> -> @+ms:U32 -> IO(Response)

GET, following redirects while left hops remain; the answer is the last response, which is a redirect only when the hops ran out or its Location is not one redirect.bend follows

def client.get.opts source · line 132 · raw

@url:String -> @headers:List<&2, 0x86ed7e1c3039a36756163ddcb16e3a95/src/http.Header> -> @ms:U32 -> @follow:Bool -> IO(Response)

GET with headers and a timeout, following redirects when follow is set

def client.timed_out source · line 141 · raw

@r:Response -> Bool

whether a response is the failure of an exchange that ran out of time

def client.get source · line 149 · raw

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

GET

def client.head source · line 153 · raw

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

HEAD (RFC 9110 §9.3.2)

def client.post source · line 157 · raw

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

POST

def client.put source · line 162 · raw

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

PUT

def client.delete source · line 167 · raw

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

DELETE

def client.options source · line 172 · raw

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

OPTIONS

def client.bearer source · line 176 · raw

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

Authorization: Bearer … (auth.bend)

def client.basic source · line 180 · raw

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

Authorization: Basic … (auth.bend; RFC 7617, RFC 4648 Base64)