https://github.com/prikhi/http-tasks
Convenience Functions for Working with HTTP Requests as Tasks.
https://github.com/prikhi/http-tasks
elm http tasks
Last synced: 3 months ago
JSON representation
Convenience Functions for Working with HTTP Requests as Tasks.
- Host: GitHub
- URL: https://github.com/prikhi/http-tasks
- Owner: prikhi
- License: mit
- Created: 2018-12-17T00:50:59.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2020-07-19T22:35:03.000Z (over 5 years ago)
- Last Synced: 2025-02-02T01:02:05.859Z (about 1 year ago)
- Topics: elm, http, tasks
- Language: Elm
- Homepage: https://package.elm-lang.org/packages/prikhi/http-tasks/latest/
- Size: 40 KB
- Stars: 5
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# HTTP Tasks
[](https://travis-ci.org/prikhi/http-tasks)
This library includes some convenience functions for building HTTP requests as
Tasks instead of Cmds, including things like making GET requests & decoding JSON:
```elm
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.