Skip to content
Convenience Functions for Working with HTTP Requests as Tasks.
Elm
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src/Http
.gitignore
.nvmrc
.travis.yml
LICENSE
README.md
elm.json
package-lock.json
package.json

README.md

HTTP Tasks

Build Status

This library includes some convenience functions for building HTTP requests as Tasks instead of Cmds, including things like making GET requests & decoding JSON:

import Http
import Http.Tasks exposing (get, resolveString, resolveJson)
import Json.Decode as Decode exposing (Decoder)
import Task exposing (Task)


type Msg
    = ReceiveData (Result Http.Error MyType)

type alias MyType =
    { fieldOne : String
    , fieldTwo : String
    }

decodeMyType : Decoder MyType
decodeMyType =
    Decode.map MyType
        |> Decode.field "fieldOne" Decode.string
        |> Decode.field "fieldTwo" Decode.string


firstTask : Task Http.Error String
firstTask =
    get
        { url = "https://some.domains.api"
        , resolver = resolveString
        }

secondTask : String -> Task Http.Error MyType
secondTask somePath =
    get
        { url = "https://some/domains.api/" ++ somePath ++ "/"
        , resolver = resolveJson decodeMyType
        }

myCommand : Cmd Msg
myCommand =
    firstTask
        |> Task.andThen secondTask
        |> Task.attempt ReceiveData

License

MIT, but exceptions possible.

You can’t perform that action at this time.