An easy to use, asynchronous, and complete Rust crate for interacting with the Adzuna API.
You can view the crate's entire documentation here. For those who are looking for the official Adzuna API docs, you can view it here.
Via cargo
, add this to your project's Cargo.toml
:
toml
[dependencies]
adzuna-rs = "1.0.0"
First, obtain an api_id
and api_key
by registering for the API. Then, you can instantiate a Client
:
```rs use adzuna::{Client, RequestBuilder};
let client = Client::new("APIID".into(), "APIKEY".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:
rs
AdzunaError {
api_error: Some(
ApiException {
exception: "AUTH_FAIL",
doc: "https://api.adzuna.com/v1/doc",
display: "Authorisation failed",
},
),
http_status: 401,
}
Getting the top companies for SWE in Texas:
rs
let companies = client
.top_companies()
.what("software engineering")
.location("US")
.location("Texas")
.fetch()
.await;
Search for UI Design jobs 5km away from Boston:
rs
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:
```rs use adzuna::models::{SortBy, SortDirection};
let jobs = client .search() .what("sales") .sortby(SortBy::Salary) .sortdir(SortDirection::Down) .fetch() .await; ```
Generate a histogram of salary data for data analyst jobs:
rs
let jobs = client
.histogram()
.what("data analyst")
.fetch()
.await;
Tests need to be ran sequentially to avoid getting rate limited. You also need to provide environmental variables for authentication:
``` APIID=123 APIKEY=abc cargo test -- --test-threads 1
```
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.