Helpers for HTTP types as part of an Interface
Create a GET HttpRequest.
Use Web.Http.addHeaders to set custom headers as needed.
Use Web.Time.onceAt to add a timeout of how long you are willing to wait before giving up.
Create a POST HttpRequest.
Use Web.Http.addHeaders to set custom headers as needed.
Use Web.Time.onceAt to add a timeout of how long you are willing to wait before giving up.
Add custom headers to the HttpRequest.
request
|> Web.Http.addHeaders
[ ( "X-Custom-Header", "ProcessThisImmediately" )
]Expect the response body to be a String.
Expect the response body to be JSON, decode it using the given decoder.
The result will either be
Err with an HttpError if it didn't succeedOk if there was a result with eitherOk with the decoded valueErr with a Json.Decode.Error
and the actual text responseDiscard the response body.
Put a given JSON value in the body of your request. This will automatically add the Content-Type: application/json header.
Put given Bytes in the body of your request.
The string argument should be a MIME type to be used in the Content-Type header
import Bytes exposing (Bytes)
import Bytes.Encode
import Time
import Web
import Zip
import Zip.Entry
exampleZipBody : Web.HttpBody
exampleZipBody =
Web.Http.bodyBytes "application/zip"
(Zip.fromEntries
[ Bytes.Encode.string "Hello, World!"
|> Bytes.Encode.encode
|> Zip.Entry.store
{ path = "hello.txt"
, lastModified = ( Time.utc, Time.millisToPosix 0 )
, comment = Nothing
}
]
|> Zip.toBytes
)
An
Interfacefor handling anHttpRequestusing the fetch API