jinjor/elm-req/1.0.0

NOTE: the latest version is 3.0.0

Rerouted (regenerated, verified). Same repository and tag, but GitHub now builds the zip with different bytes, so it no longer matches the SHA-1 package.elm-lang.org recorded. The Lamdera package server serves a copy recovered from https://github.com/jinjor/elm-req.

What we checked: Tag 1.0.0 is still on github.com/jinjor/elm-req; its commit df124f1a72a5 is from 2018-12-01 14:29 UTC, before the version was published (2018-12-01 14:34 UTC); elm.json is byte-identical to package.elm-lang.org's; the exposed modules match docs.json; the zip's SHA-1 is not the published one (GitHub's zip no longer comes out byte for byte the same), so the contents were checked instead.

The Lamdera compiler uses this copy and prints a one-line notice saying so. elm itself fails to download this version.

Details · package.elm-lang.org's zip: https://github.com/jinjor/elm-req/zipball/1.0.0/

Req

An experimental alternative for elm/http.

See more details in elm/http.

Types

type alias Req =
{ method : String
, url : String
, headers : List ( String, String )
, body : Body
, timeout : Maybe Float
, allowCookiesFromOtherDomains : Bool
}

Request

type Body
= EmptyBody
| StringBody String String
| JsonBody Value
| FileBody File
| BytesBody String Bytes
| MultipartBody (List Part)

Body

type Part
= StringPart String String
| FilePart String File
| BytesPart String String Bytes

Part

Methods

init : String -> String -> Req

Arbitrary method

get : String -> Req

GET

post : String -> Req

POST

put : String -> Req

PUT

patch : String -> Req

PATCH

delete : String -> Req

DELETE

Body

withStringBody : String -> String -> Req -> Req

Add text with mime type.

withJsonBody : Value -> Req -> Req

Add JSON for POST etc.

withFileBody : File -> Req -> Req

Add file to upload

withBytesBody : String -> Bytes -> Req -> Req

Add bytes with mime type.

withMultipartBody : List Part -> Req -> Req

Add multipart body.

Parts

stringPart : String -> String -> Part

String part (key and value)

filePart : String -> File -> Part

String part (key and file)

bytesPart : String -> String -> Bytes -> Part

Bytes part (key and mime and bytes)

Options

withHeader : String -> String -> Req -> Req

Add header

withTimeout : Float -> Req -> Req

Add timeout

allowCookiesFromOtherDomains : Bool -> Req -> Req

Allow cookies from other domains.

Task

stringTask : (Req -> Response String -> Result x a) -> Req -> Task x a

Create a task to parse string body.

bytesTask : (Req -> Response Bytes -> Result x a) -> Req -> Task x a

Create a task to parse bytes body.

whateverTask : msg -> Req -> Task x msg

Ignore the result.

toTask : Resolver x a -> Req -> Task x a

Create a task with existing Http.Resolver.

Resolver

simplyResolveJson : Decoder a -> Req -> Response String -> Result Error a

Make a resolver function that returns Http.Error.

getUserSimple : String -> Task Http.Error User
getUserSimple userName =
    Req.get ("https://api.github.com/users/" ++ userName)
        |> Req.stringTask (Req.simplyResolveJson userDecoder)

Tracking

String
-> (Result x a -> msg)
-> (Req -> Response String -> Result x a)
-> Req
-> Cmd msg

Track progress of responses with string body.

String
-> (Result x a -> msg)
-> (Req -> Response Bytes -> Result x a)
-> Req
-> Cmd msg

Track progress of responses with bytes body.

trackWhatever : String -> (Result Never () -> msg) -> Req -> Cmd msg

Track something but ignore the result.

track : String -> Expect msg -> Req -> Cmd msg

Make a traking Cmd using existing Http.Expect.