Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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 6 years ago)
- Default Branch: master
- Last Pushed: 2020-07-19T22:35:03.000Z (over 4 years ago)
- Last Synced: 2024-04-16T06:58:52.259Z (9 months 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
[![Build Status](https://travis-ci.org/prikhi/http-tasks.svg?branch=master)](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.stringfirstTask : 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.