tallgrass/client

Types

Client is the basic type used to make requests. Client should be initialized with client.new and provided with the desired cache and pagination options via with_cache and with_pagination.

pub opaque type Client

Paginated endpoints accept limit and offset query parameters.

Example

let client = pokemon.new()

// Sets the limit to 100
client |> with_pagination(Limit(100)) |> pokemon.fetch()

// Sets the offset to 20
client |> with_pagination(Offset(20)) |> pokemon.fetch()

// Sets the limit to 100 and the offset to 20
client |> with_pagination(Paginate(100, 20)) |> pokemon.fetch()
pub type PaginationOptions {
  Default
  Limit(Int)
  Offset(Int)
  Paginate(limit: Int, offset: Int)
}

Constructors

  • Default
  • Limit(Int)
  • Offset(Int)
  • Paginate(limit: Int, offset: Int)

Functions

pub fn new() -> Client

Initializes a Client with no cache and default pagination settings.

pub fn next(
  client: Client,
  page: PaginatedResource,
) -> Result(PaginatedResource, Error)

Follows the next link of a given PaginatedResource and returns an error if the next link is null.

Example

let client = client.new()
use res <- result.try(client |> pokemon.fetch())
client |> client.next(res)
pub fn previous(
  client: Client,
  page: PaginatedResource,
) -> Result(PaginatedResource, Error)

Follows the previous link of a given PaginatedResource and returns an error if the previous link is null.

Example

let client = client.new()
use res <- result.try(client |> pokemon.fetch())
client |> client.previous(res)
pub fn with_cache(client: Client, cache: Cache) -> Client

Returns a Client with the provided Cache.

pub fn with_pagination(
  client: Client,
  pagination: PaginationOptions,
) -> Client

Returns a Client with the provided pagination options.

Search Document