Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fabienhenon/jsonapi-http-retry
Retry failed jsonapi requests with retry policies
https://github.com/fabienhenon/jsonapi-http-retry
elm elm-lang http jsonapi remotedata retry
Last synced: about 1 month ago
JSON representation
Retry failed jsonapi requests with retry policies
- Host: GitHub
- URL: https://github.com/fabienhenon/jsonapi-http-retry
- Owner: FabienHenon
- License: mit
- Created: 2020-04-15T10:39:37.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-09-27T15:15:49.000Z (about 3 years ago)
- Last Synced: 2024-11-21T00:59:30.769Z (about 1 month ago)
- Topics: elm, elm-lang, http, jsonapi, remotedata, retry
- Language: Elm
- Homepage: https://package.elm-lang.org/packages/FabienHenon/jsonapi-http-retry/latest/
- Size: 8.79 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# jsonapi-http-retry
Retry failed jsonapi requests with retry policies.
It is greatly inspired by the [`Retry` package](https://package.elm-lang.org/packages/choonkeat/elm-retry/latest/) but aims to handle http requests from the [`jsonapi-http` package](https://package.elm-lang.org/packages/calions-app/jsonapi-http/latest/).
With this package you can add retry policies to [`jsonapi-http`](https://package.elm-lang.org/packages/calions-app/jsonapi-http/latest/) requests errors.
You can choose specific errors that will trigger a retry: unauthenticated error, network error, etc...You can also send `Cmd`s between 2 failures with the `Http.CmdRetry` module.
## Getting Started
Here is an example retrying requests 5 times maximum with a constant interval between retries, only for unauthenticated and unauthorized errors:
```elm
import Http.Request
import Http.Retry
import Json.Encode
import JsonApi.Decoderequest : Cmd Msg
request =
Request.request
{ url = "http://endpoint"
, headers = []
, body = Json.Encode.object []
, documentDecoder = JsonApi.Decode.resources "resource-type" entityDecoder
}
|> Http.Retry.with
[ Http.Retry.maxRetries 5
, Http.Retry.exponentialBackoff { interval = 500, maxInterval = 3000 }
]
[ Http.Retry.onUnauthenticatedStatus
, Http.Retry.onUnauthorizedStatus
]
|> Task.perform OnTaskCompleted
```