An HTTP request/response parser and serializer for Carp.
(load "git@github.com:carpentry-org/http@0.1.0")(match (Request.parse "GET / HTTP/1.1\r\nHost: example.com\r\n\r\n")
(Result.Success req)
(println* (Request.verb &req) " " &(URI.str (Request.uri &req)))
(Result.Error e) (IO.errorln &e))(match (Response.parse "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\nhello")
(Result.Success resp)
(println* (Response.code &resp) " " (Response.body &resp))
(Result.Error e) (IO.errorln &e))(let [req (Request.get (URI.zero) [] {} @"")]
(println* &(Request.str &req)))(match (Request.header &req "content-type")
(Maybe.Just ct) (println* "Content-Type: " &ct)
(Maybe.Nothing) (println* "no content-type"))(match (Form.parse "name=carp&version=1")
(Result.Success m)
(println* "name=" &(Map.get &m "name"))
_ ())Status.ok ; => 200
Status.not-found ; => 404
(Status.reason 200) ; => "OK"| Type | Purpose |
|---|---|
Request |
HTTP request (verb, version, URI, headers, cookies, body) |
Response |
HTTP response (code, message, version, headers, cookies, body) |
Cookie |
HTTP cookie with attributes |
SameSite |
Cookie SameSite attribute (Lax, Strict, None) |
Status |
Status code constants and reason phrases |
Form |
URL-encoded form body parser |
carp -x test/http.carp
You can find the API documentation online!
Have fun!