Skip to content

@http

Import this module with import @http.

HTTP client for making requests. Currently supports HTTP only.

Function Signature Description
get (url string, headers map[string:string]) -> (HttpResponse, Error) GET request — always use destructuring
post (url string, body string, headers map[string:string]) -> (HttpResponse, Error) POST request — always use destructuring
put (url string, body string, headers map[string:string]) -> (HttpResponse, Error) PUT request — always use destructuring
patch (url string, body string, headers map[string:string]) -> (HttpResponse, Error) PATCH request — always use destructuring
delete (url string, headers map[string:string]) -> (HttpResponse, Error) DELETE request — always use destructuring
head (url string, headers map[string:string]) -> (HttpResponse, Error) HEAD request — always use destructuring

get, post, put, patch, delete, and head are fallible: single-variable assignment is a compile-time error (E3089); the result must be destructured (mut resp, err = ... or mut resp, _ = ...).

HttpResponse is one type shared by @http and @server: it is available when either is imported, and HttpResponse, http.HttpResponse and server.HttpResponse all name it. A server handler can return a response from http.get unchanged.

Field Type Description
status i64 HTTP status code
body string Response body
headers map[string:string] Response headers; the content type is headers["Content-Type"]