#api-wrapper #api-client #async-api #api-bindings #jobs-api

adzuna

An easy to use, asynchronous, and complete API wrapper for interacting with the Adzuna API

3 stable releases

1.0.2 Feb 6, 2023

#116 in #api-wrapper

GPL-3.0-only

31KB
610 lines

Adzuna API Wrapper

An easy to use, asynchronous, and complete Rust crate for interacting with the Adzuna API.

Documentation Crate GPLv3 License

Installation

Via cargo, add this to your project's Cargo.toml:

[dependencies]
adzuna-rs = "1.0.2"

Usage

First, obtain an api_id and api_key by registering for the API. Then, you can instantiate a Client:

use adzuna::{Client, RequestBuilder};

let client = Client::new("API_ID".into(), "API_KEY".into());

We also have to import the RequestBuilder trait to invoke .fetch() on the built requests.

You can access all the endpoints from this client. Calling an endpoint will return a request builder, which allows you to chain calls for idiomatic query parameter configuration.

After customizing the query, you have to call .fetch(), which asynchronously sends the request and returns the data in a Result<T, AdzunaError>. AdzunaError optionally contains more information about the error returned by the API as such:

AdzunaError {
    api_error: Some(
        ApiException {
            exception: "AUTH_FAIL",
            doc: "https://api.adzuna.com/v1/doc",
            display: "Authorisation failed",
        },
    ),
    http_status: 401,
}

Examples

Getting the top companies for SWE in Texas:

let companies = client
    .top_companies()
    .what("software engineering")
    .location("US")
    .location("Texas")
    .fetch()
    .await;

Search for UI Design jobs 5km away from Boston:

let jobs = client
    .search()
    .what("ui design")
    .where("boston")
    .distance(5)
    .fetch()
    .await;

Search for part time sales jobs sorted by salary in descending order:

use adzuna::models::{SortBy, SortDirection};

let jobs = client
    .search()
    .what("sales")
    .sort_by(SortBy::Salary)
    .sort_dir(SortDirection::Down)
    .fetch()
    .await;

Generate a histogram of salary data for data analyst jobs:

let jobs = client
    .histogram()
    .what("data analyst")
    .fetch()
    .await;

Running Tests

Tests need to be ran sequentially to avoid getting rate limited. You also need to provide environmental variables for authentication:

API_ID=123 API_KEY=abc cargo test -- --test-threads 1

Contributing

Contributions are always welcome! This crate currently covers all the endpoints mentioned in the official documentation, but if you see something missing or encounter a bug, feel free to open an issue or create a pull request.

Dependencies

~7–19MB
~255K SLoC