Http
Functions
Aborts all running requests.
Http.abortAll()
Creates a request record where the method is DELETE
request =
Http.delete("https://httpbin.org/delete")
request.method == "DELETE"
Creates an empty request record. It is useful if you want to use a non- standard HTTP method.
Http.empty() ==
{
withCredentials = false,
method = "GET",
body = `null`,
headers = [],
url = ""
}
Sets the body of the request to the given string
formData =
FormData.empty()
|> FormData.addString("key", "value")
"https://httpbin.org/anything"
|> Http.post()
|> Http.formDataBody(formData)
|> Http.send()
Creates a request record where the method is GET
request =
Http.get("https://httpbin.org/get")
request.method == "GET"
Checks the prescence of a header with the given key.
Http.empty()
|> Http.header("Content-Type", "application/json")
|> Http.hasHeader("Content-Type")
Adds a header to the request with the given key and value. Overwrites the value if key already exists.
Http.empty()
|> Http.header("Content-Type", "application/json")
Sets the body of the request to the given object encoded to JSON
"https://httpbin.org/anything"
|> Http.post()
|> Http.jsonBody(encode { name = "John" })
|> Http.send()
Sets the method of the request to the given one.
Http.empty()
|> Http.method("PATCH")
Creates a request record where the method is POST
request =
Http.post("https://httpbin.org/post")
request.method == "POST"
Creates a request record where the method is PUT
request =
Http.put("https://httpbin.org/put")
request.method == "PUT"
Returns all running requests.
Sends the request with a generated unique ID.
"https://httpbin.org/get"
|> Http.get()
|> Http.send()
Sends the request with the given ID so it could be aborted later.
"https://httpbin.org/get"
|> Http.get()
|> Http.sendWithId("my-request")
Sets the body of the request to the given string
"https://httpbin.org/anything"
|> Http.post()
|> Http.stringBody("Some string that will come back.")
|> Http.send()
Sets the URL of the request to the given one.
Http.empty()
|> Http.url("https://httpbin.org/anything")
Sets the withCredentials of the request to the given one.
Http.empty()
|> Http.withCredentials(true)