Pexels API
Pexels API is a Rust library for interacting with the Pexels API. It allows you to search for photos, videos, and collections, as well as retrieve individual media items by their ID.
Features
- Search for photos and videos
- Retrieve individual photos and videos by ID
- Search for collections
- Retrieve featured collections
- Supports asynchronous operations
Installation
Add the following to your Cargo.toml:
[]
= "0.15.7"
= { = "0.0.5" }
= { = "0.12.11", = ["json"] }
= { = "1.0.217", = ["derive"] }
= "1.0.135"
= "2.0.9 "
= { = "1", = ["full"] }
= "2.5.4"
Usage
Before using the library, make sure to set your Pexels API key in a .env file:
PEXELS_API_KEY=your_api_key_here
Example
Here is a basic example of how to use the library:
use dotenv;
use ;
use env;
async
API Documentation
Pexels
The main client for interacting with the Pexels API.
Methods
new(api_key: String) -> Self: Creates a new Pexels client.search_photos(query: &str, per_page: usize, page: usize) -> Result<PhotosResponse, PexelsError>: Searches for photos.get_photo(id: u32) -> Result<Photo, PexelsError>: Retrieves a photo by its ID.search_videos(query: &str, per_page: usize, page: usize) -> Result<VideosResponse, PexelsError>: Searches for videos.get_video(id: u32) -> Result<Video, PexelsError>: Retrieves a video by its ID.search_collections(per_page: usize, page: usize) -> Result<CollectionsResponse, PexelsError>: Searches for collections.
search_media(query: &str, per_page: usize, page: usize, media_type: MediaType, sort: MediaSort) -> Result<MediaResponse, PexelsError>:
Searches for media.
Documentation
For detailed documentation, please refer to Documentation.
License
Licensed under either of
- Apache License, Version 2.0, LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0
- MIT license LICENSE-MIT or http://opensource.org/licenses/MIT
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 or MIT license, shall be dual licensed as above, without any additional terms or conditions.