Try Install Learn Blog API Packages GitHub
Pages
core

Search
Entities

Http

Functions

Aborts all running requests.

Http.abortAll()
delete
(
urlValue
:
String
)
:
Http.Request

Creates a request record where the method is DELETE

request =
  Http.delete("https://httpbin.org/delete")

request.method == "DELETE"
empty
:
Http.Request

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 = ""
  }
formDataBody
(
request
:
Http.Request
body
:
FormData
)
:
Http.Request

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()
get
(
urlValue
:
String
)
:
Http.Request

Creates a request record where the method is GET

request =
  Http.get("https://httpbin.org/get")

request.method == "GET"
hasHeader
(
request
:
Http.Request
key
:
String
)
:
Bool

Checks the prescence of a header with the given key.

Http.empty()
|> Http.header("Content-Type", "application/json")
|> Http.hasHeader("Content-Type")
header
(
request
:
Http.Request
key
:
String
value
:
String
)
:
Http.Request

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")
jsonBody
(
request
:
Http.Request
body
:
Object
)
:
Http.Request

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()
method
(
request
:
Http.Request
method
:
String
)
:
Http.Request

Sets the method of the request to the given one.

Http.empty()
|> Http.method("PATCH")
post
(
urlValue
:
String
)
:
Http.Request

Creates a request record where the method is POST

request =
  Http.post("https://httpbin.org/post")

request.method == "POST"
put
(
urlValue
:
String
)
:
Http.Request

Creates a request record where the method is PUT

request =
  Http.put("https://httpbin.org/put")

request.method == "PUT"
requests
:
Map(String, Http.NativeRequest)

Returns all running requests.

send
(
request
:
Http.Request
uid
:
String
)
:
Promise(Result(Http.ErrorResponse, Http.Response))

Sends the request with a unique ID (generated by default) so it could be aborted later.

"https://httpbin.org/get"
|> Http.get()
|> Http.sendWithId("my-request")
stringBody
(
request
:
Http.Request
body
:
String
)
:
Http.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()
url
(
request
:
Http.Request
url
:
String
)
:
Http.Request

Sets the URL of the request to the given one.

Http.empty()
|> Http.url("https://httpbin.org/anything")
withCredentials
(
request
:
Http.Request
value
:
Bool
)
:
Http.Request

Sets the withCredentials of the request to the given one.

Http.empty()
|> Http.withCredentials(true)