Crate aletheia

Crate aletheia 

Source
Expand description

Aletheia is a client library for the Guardian’s content API.

It is built on top of reqwest and provides a similar interface for building queries. Responses returned by the client are deserialized into structs that mirror the types used by the API.

Aletheia provides both an asynchronous client (default) and a blocking client, which can be enabled with the blocking feature.

Keys to query the API can be obtained at https://open-platform.theguardian.com/access/

More information on the API can be found at https://open-platform.theguardian.com/documentation/

§Async example

Executing the code below requires an asynchronous context. For example, it can be executed from within an async fn block.

let client = GuardianContentClient::new("YOUR_API_KEY");

let response = client
    .build_request()
    .search("Elections")
    .page_size(10)
    .show_fields(vec![Field::Byline, Field::LastModified])
    .order_by(OrderBy::Newest)
    .order_date(OrderDate::Published)
    .send()
    .await?;

println!("{:#?}", response.results);

§Blocking example

Executing the code below requires a blocking context and the blocking feature enabled.

§Warning

Using the blocking client in an async context will cause a panic. If you need to use the blocking client in an async function, you can do so in a blocking context, for example by using tokio::task::spawn_blocking.

let client = GuardianContentClient::new("YOUR_API_KEY");

let response = client
    .build_request()
    .search("Elections")
    .page_size(10)
    .show_fields(vec![Field::Byline, Field::LastModified])
    .order_by(OrderBy::Newest)
    .order_date(OrderDate::Published)
    .send()?;

println!("{:#?}", response.results);

Modules§

enums
Enum types that prevent passing illegal parameters to the Guardian’s content API.
error
Error variants.
structs
Structs for deserializing the Guardian’s content API responses.

Structs§

GuardianContentClient
The client used to send requests to the Guardian’s content API. This client maintains a private internal asynchronous client implemented by reqwest::Client. Note that use of this client requires an asychronous context. If your application does not run asynchronously (for example if the tokio runtime is not available), consider enabling the blocking feature of this crate, which will transform this into a blocking client.
GuardianRequestBuilder