Title here
Summary here
A module to play with HTTP requests, using cpp-httplib (MIT License).
Disclaimer: this module does not handle
Create a header map to use with the http client.
Parameters They work as pairs with:
name: stringvalue: stringReturn value UserType<httpHeaders>
Author
Example
(let headers (http:headers
# pair 0
"Accept-Encoding" "gzip, deflate"
# pair 1
"Content-Type" "application/json"))
Create a http client to query a server.
Parameters
host: stringport: number (optional if the protocol is in the host (http:// or https://))Return value httpClient
Author
Example
(let cli (http:client "localhost" 1234))
Get content from an online resource.
Parameters
client: UserType<httpClient>route: stringheaders: UserType<httpHeaders>, optional, always come lastReturn value List if the request succeeded: [status, body], otherwise nil
Author
Example
(let headers (http:headers:create
"Accept-Encoding" "gzip, deflate"))
(let cli (http:client "localhost" 1234))
(mut output (http:get cli "/hi" headers))
(if (nil? output)
(print "couldn't reach the server")
(print (@ output 0))) # print the status
Make a POST / PUT / PATCH / DELETE request with a String as the request’s body.
Parameters
client: UserType<httpClient>route: stringbody: string (request body)mimetype: string, optional (defaults to text/plain)headers: UserType<httpHeaders>, optional, always come lastReturn value List if the request succeeded: [status, body], otherwise nil
Author
Example
(let cli (http:client "localhost" 1234))
(mut output (http:post cli "/hi" "{\"key\": 5}" "application/json" headers))
(if (nil? output)
(print "couldn't reach the server")
(print (@ output 0))) # print the status