| Crates.io | congressdotgov_rs |
| lib.rs | congressdotgov_rs |
| version | 0.3.1 |
| created_at | 2025-01-04 04:44:20.101473+00 |
| updated_at | 2025-03-17 17:25:50.147606+00 |
| description | congress.gov API bindings. |
| homepage | |
| repository | https://github.com/Wollaston/congressdotgov_rs |
| max_upload_size | |
| id | 1503653 |
| size | 302,172 |
Rust bindings to the congress.gov REST API. Inspired by Designing Rust bindings for REST APIs.
These are unofficial bindings and are not affiliated with congress.gov
use serde::Deserialize;
use congressdotgov_rs::Cdg;
use congressdotgov_rs::api::Query;
use congressdotgov_rs::api::bill;
use congressdotgov_rs::api::common::Format;
use congressdotgov_rs::Auth;
use tokio_test::block_on;
// The return type of a `Bill`. Note that a Bill may contain more information, but you can
// define your structure to only deserialize what is needed as the return value is a
// serde_json::Value.
#[derive(Debug, Deserialize)]
struct Bills {
bills: Vec<Bill>,
}
#[derive(Debug, Deserialize)]
struct Bill{
title: String,
number: String,
}
// Create the client.
let auth = Auth::Token("API_KEY".into());
let req_client = reqwest::Client::new();
let client = Cdg::new(auth, req_client, Format::Json).unwrap();
// Create a simple endpoint. This one gets recent Bills from the 118th Congress.
let endpoint = bill::Congress::builder().congress(118_u8).build().unwrap();
// Call the endpoint. The return type decides how to represent the value.
# tokio_test::block_on(async {
let bills: Bills = endpoint.query(&client).await.unwrap();
# })
All resources, endpoints, and their respective query parameters are covered by these bindings. Many parameters are defined by Rust types, and the library strives to be idiomatic.
These resources are:
These bindings were created to make it easier to query the congress.gov API from Rust web servers for use in NLP and related tasks. I hope others may also find them useful.