correl/elm-paginated/1.0.1

NOTE: this package is not compatible with Elm 0.19.1

Paginated

A library for Facilitates fetching data from a paginated JSON API.

Requests and Responses

type Request a

Encapsulates an API request for a list of items of type a.

type Response a
= Partial (Request a) (List a)
| Complete (List a)

Describes an API response.

A response may either be Partial (there are more pages of results yet to be fetched), or Complete (all records have been fetched). The response includes all of the items fetched in order.

get : String -> Decoder a -> Request a

Build a GET request.

post : String -> Body -> Decoder a -> Request a

Build a POST request.

Custom requests

type alias RequestOptions a =
{ method : String
, headers : List Header
, url : String
, body : Body
, decoder : Decoder a
, timeout : Maybe Time
, withCredentials : Bool
}

Describes an API request.

request : RequestOptions a -> Request a

Create a custom request, allowing the specification of HTTP headers and other options. For example:

Paginated.request
    { method = "GET"
    , headers = [Http.header "Private-Token" "XXXXXXXXXXXXXXXX"]
    , url = url
    , body = Http.emptyBody
    , decoder = decoder
    , timeout = Nothing
    , withCredentials = False
    }

Converting

httpRequest : Request a -> Request (Response a)

Convert a Request to a Http.Request that can then be sent via Http.send.

Sending requests

send : (Result Error (Response a) -> msg) -> Request a -> Cmd msg

Send a Request.

Handling responses

type Response a
= Partial (Request a) (List a)
| Complete (List a)

Describes an API response.

A response may either be Partial (there are more pages of results yet to be fetched), or Complete (all records have been fetched). The response includes all of the items fetched in order.

update : Response a -> Response a -> Response a

Append two paginated responses, collecting the results within.