correl / elm-paginated / 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.

get : String -> Json.Decode.Decoder a -> Request a

Build a GET request.

post : String -> Http.Body -> Json.Decode.Decoder a -> Request a

Build a POST request.

Custom requests


type alias RequestOptions a =
{ method : String
, headers : List Http.Header
, url : String
, body : Http.Body
, decoder : Json.Decode.Decoder a
, timeout : Maybe Basics.Float
, withCredentials : Basics.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
    }

Sending requests

send : (Result Http.Error (List a) -> msg) -> Request a -> Platform.Cmd.Cmd msg

Send a Request.

Low-Level operations

toTask : Request a -> Task Http.Error (List a)

Convert a Request into a Task.

This is only really useful if you want to chain together a bunch of requests (or any other tasks) in a single command.