Try Install Learn Blog Api Packages Github
Pages

Http

Module for sending HTTP requests.

sequence {
  response =
    "https://httpbin.org/get"
    |> Http.get()
    |> Http.send()

  Debug.log(response)
} catch Http.ErrorResponse => error {
  Debug.log(error)
}

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
(
body
:
FormData
request
:
Http.Request
)
:
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"
header
(
key
:
String
value
:
String
request
:
Http.Request
)
:
Http.Request

Adds a header to the request with the given key and value.

Http.empty()
|> Http.header("Content-Type", "application/json")
jsonBody
(
body
:
Object
request
:
Http.Request
)
:
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
(
method
:
String
request
:
Http.Request
)
:
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 requuests.

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

Sends the request with a generated unique id.

"https://httpbin.org/get"
|> Http.get()
|> Http.send()
sendWithID
(
uid
:
String
request
:
Http.Request
)
:
Promise(Http.ErrorResponse, Http.Response)

Sends the request with the given ID so it could be aborted later.

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

Sets the URL of the request to the given one.

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

Sets the withCredentials of the request to the given one.

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