loc-api
loc-api is a Rust library that provides a comprehensive interface for interacting with the Library of Congress (LOC) APIs. It simplifies the process of constructing API requests, managing parameters, and handling responses, enabling developers to seamlessly integrate LOC data into their Rust applications.
Features
- Comprehensive Endpoint Support: Access various LOC API endpoints such as search, collections, items, and resources.
- Flexible Parameter Management: Easily construct and customize query parameters, including filtering, sorting, and formatting options.
- Robust Response Models: Utilize well-defined Rust structures to parse and interact with LOC API responses.
- High-Level API Client: Engage with LOC APIs through an
ApiClientthat handles endpoint construction and HTTP requests. - Customizable Configurations: Override default settings like the base URL for testing or alternative deployments.
Table of Contents
Installation
Add loc-api to your project's Cargo.toml:
[]
= "*"
OR
You can use cargo add to add the dependency to your Cargo.toml:
This library depends on reqwest, serde and serde_json for making HTTP requests and serializing/deserializing JSON data, respectively:
[]
= { = "0.11", = ["blocking", "json"] }
= { = "1.0", = ["derive"] }
= "1.0"
Usage
Creating an API Client
First, initialize the ApiClient. You can optionally set the LOC_API_BASE_URL environment variable to override the default LOC API base URL.
Other methods of setting the base URL include using the ApiClient::with_base_url constructor or directly modifying the simple_builders::DEFAULT_BASE_URL constant.
use ApiClient;
Performing a Search
Use the search method to perform general searches across the LOC website.
use ApiClient;
use FacetReq;
use AttributesSelect;
use SortField;
Retrieving an Item
Fetch detailed information about a specific item using its item_id.
use ApiClient;
use ItemAttributes;
Fetching a Specific Format
Retrieve items of a specific format, such as maps or books.
use ApiClient;
use FacetReq as FRequest;
use ;
use FormatType;
Managing Collections
Retrieve All Collections
Fetch all available collections from the LOC API.
use ApiClient;
use FacetReq as FRequest;
use ;
Retrieve a Specific Collection
Fetch detailed information about a specific collection using its name.
use ApiClient;
use FacetReq as FRequest;
use ;
Modules
endpoints
LOC API endpoints, providing enums and methods to construct URLs based on different endpoints and parameters.
param_models
Contains structures representing query parameters applicable to multiple endpoints, such as CommonParams, SearchParams, ItemParams, and ResourceParams.
attribute_models
Defines the possible attributes for query parameters that can be used in API requests, including structures like AttributesSelect and enums for sorting fields.
format_models
Represents the possible response formats (JSON or YAML) and specific media types for endpoints like audio, books, maps, etc.
response_models
Structures that model the responses from LOC API endpoints, such as SearchResultResponse, ItemResponse, FormatResponse, and others.
simple_builders
Provides a high-level ApiClient for interacting with the LOC API, abstracting endpoint construction, parameter management, and HTTP requests.
License
This project is licensed under the MIT License. See the LICENSE file for more details.