(sigil http client)
(sigil http client) - HTTP Client Implementation
Provides HTTP/1.1 client functionality for making requests to HTTP and HTTPS servers.
Example: (import (sigil http client)) (let ((response (http-get "https://example.com/"))) (display (http-response-body response)))
Exports
urlprocedureConstruct a url struct.
url?procedureTest if a value is a url struct.
url-schemeprocedureGet the scheme field of a url struct.
url-hostprocedureGet the host field of a url struct.
url-portprocedureGet the port field of a url struct.
url-pathprocedureGet the path field of a url struct.
url-queryprocedureGet the query field of a url struct.
parse-urlprocedureParse a URL string into a url record Supports: http://host:port/path?query and https://...
connect-to-serverprocedureConnect to a server, using TLS if scheme is https Returns connection object or #f on failure
conn-writeprocedureWrite data to connection (socket or TLS)
conn-readprocedureRead data from connection (socket or TLS)
conn-closeprocedureClose connection
build-request-stringprocedureBuild HTTP request string
build-header-linesprocedureBuild header lines from headers (dict or alist)
parse-status-lineprocedureParse HTTP status line Returns (version status-code reason) or #f
parse-response-headersprocedureParse response headers from data Returns dict with keyword keys
read-http-responseprocedureRead HTTP response from connection Returns http-response or #f on error
read-all-dataprocedureRead all data from connection until closed
parse-http-responseprocedureParse HTTP response from string
decode-chunked-bodyprocedureDecode chunked transfer encoding Format: <hex-size>rn<data>rn ... 0rnrn
find-crlfprocedureFind position of rn starting at pos
hex-string->numberprocedureConvert hex string to number
find-header-endprocedureFind the end of HTTP headers (position of rnrn)
skip-crlfprocedureSkip CRLF sequence(s) at position
http-response-jsonprocedureParse HTTP response body as JSON.
Returns the parsed JSON value, or #f if the response is #f or parsing fails. Requires sigil-json package.
(let ((res (http-get "https://api.example.com/data")))
(http-response-json res))
; => #{ users: #[...] count: 42 }http-requestprocedureHTTP Request Record Uses define-struct for immutability and functional updates via inherit
Re-exported from (sigil http request)
http-response?procedureTest if a value is a http-response struct.
Re-exported from (sigil http response)
http-response-statusprocedureGet the status field of a http-response struct.
Re-exported from (sigil http response)
http-response-headersprocedureGet the headers field of a http-response struct.
Re-exported from (sigil http response)
http-response-bodyprocedureGet the body field of a http-response struct.
Re-exported from (sigil http response)