http
Making HTTP requests
The functions of nanyx.http.core/http make HTTP requests, each requiring Http. Import the module under
its own name, import nanyx.http.core/http as http, to call them as http.get, http.post and http.send. Each
waits for the response, and gives it, or why there was none as an HttpError:
match http.post("https://example.com/notes", "Buy milk")
| #some(response) -> println("{response.status}: {response.body}")
| #error(#timeout) -> println("No answer in time")
| #error(#connectionFailed(why)) -> println("Couldn't connect: {why}")
| #error(_) -> println("The request failed")
http.send takes a whole Request, for another method, headers or a timeout of its own:
def request = Request.of(#put, "https://example.com/notes/1") with headers = [("Content-Type", "text/plain")]
match http.send(request with body = "Buy eggs")
| #some(response) -> println(response.status)
| #error(_) -> println("The request failed")
Reference
Making HTTP requests.
Each function requires Http, waits for the response, and gives it, or why there was
none as an HttpError. Import the module as import nanyx.http.core/http as http to
call http.get, http.post and http.send by those names.
send
def send: [Async, Http] Request -> #some(Response) | #error(HttpError)
Sends request, and gives its response.
get
def get: [Async, Http] string -> #some(Response) | #error(HttpError)
Gets url, and gives the response.
post
def post: [Async, Http] string, string -> #some(Response) | #error(HttpError)
Posts body to url, and gives the response.