Skip to main content

PexelsClient

Struct PexelsClient 

Source
pub struct PexelsClient { /* private fields */ }
Expand description

Main client for the Pexels API

This client provides methods to interact with all endpoints of the Pexels API and handles authentication, request building and response parsing.

Implementations§

Source§

impl PexelsClient

Source

pub fn new<S: Into<String>>(api_key: S) -> Self

Creates a new PexelsClient with the provided API key

§Arguments
  • api_key - The Pexels API key
§Returns

A new instance of PexelsClient

§Example
use pexels_api::PexelsClient;

let client = PexelsClient::new("your_api_key");
Source

pub fn with_config<S: Into<String>>( api_key: S, timeout: u64, max_idle_connections: usize, ) -> Self

Creates a new PexelsClient with custom configuration

§Arguments
  • api_key - The Pexels API key
  • timeout - Request timeout in seconds
  • max_idle_connections - Maximum number of idle connections per host
§Returns

A new instance of PexelsClient

Source

pub fn with_base_url<S: Into<String>>(self, base_url: S) -> Self

Sets a custom base URL for the Pexels API

§Arguments
  • base_url - The custom base URL
§Returns

Self for method chaining

Source

pub async fn search_photos( &self, query: &str, params: &SearchParams, ) -> Result<PhotosPage, PexelsError>

Search for photos matching the specified query and parameters

§Arguments
  • query - The search query
  • params - Additional search parameters (pagination, filters, etc.)
§Returns

A Result containing the photos search response or an error

§Example
use pexels_api::{PexelsClient, SearchParams,Size};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = PexelsClient::new("your_api_key");
    let params = SearchParams::new()
        .page(1)
        .per_page(15)
        .size(Size::Large);

    let photos = client.search_photos("nature", &params).await?;
    println!("Found {} photos", photos.total_results);
    Ok(())
}
Source

pub async fn curated_photos( &self, params: &PaginationParams, ) -> Result<PhotosPage, PexelsError>

Fetch curated/featured photos

§Arguments
  • params - Pagination parameters
§Returns

A Result containing the curated photos response or an error

Source

pub async fn get_photo(&self, id: u64) -> Result<Photo, PexelsError>

Get a specific photo by its ID

§Arguments
  • id - The photo ID
§Returns

A Result containing the photo or an error

Source

pub async fn search_videos( &self, query: &str, params: &VideoSearchParams, ) -> Result<VideosPage, PexelsError>

Search for videos matching the specified query and parameters

§Arguments
  • query - The search query
  • params - Additional search parameters (pagination, filters, etc.)
§Returns

A Result containing the videos search response or an error

Source

pub async fn popular_videos( &self, params: &PaginationParams, ) -> Result<VideosPage, PexelsError>

Fetch popular videos

§Arguments
  • params - Pagination parameters
§Returns

A Result containing the popular videos response or an error

Source

pub async fn popular_videos_with_params( &self, params: &PopularVideoParams, ) -> Result<VideosPage, PexelsError>

Fetch popular videos with documented filters.

§Arguments
  • params - Pagination, size and duration filters
§Returns

A Result containing the popular videos response or an error

Source

pub async fn get_video(&self, id: u64) -> Result<Video, PexelsError>

Get a specific video by its ID

§Arguments
  • id - The video ID
§Returns

A Result containing the video or an error

Source

pub async fn get_collections( &self, params: &PaginationParams, ) -> Result<CollectionsPage, PexelsError>

Get collections list

§Arguments
  • params - Pagination parameters
§Returns

A Result containing the collections response or an error

Get featured collections list

§Arguments
  • params - Pagination parameters
§Returns

A Result containing the featured collections response or an error

Source

pub async fn get_collection_media( &self, id: &str, params: &PaginationParams, ) -> Result<MediaPage, PexelsError>

Get collection media items (photos and videos)

§Arguments
  • id - The collection ID
  • params - Pagination parameters
§Returns

A Result containing the media response or an error

Source

pub async fn get_collection_media_with_params( &self, id: &str, params: &CollectionMediaParams, ) -> Result<MediaPage, PexelsError>

Get collection media items (photos and videos) with documented filters

§Arguments
  • id - The collection ID
  • params - Pagination, media type and sort filters
§Returns

A Result containing the media response or an error

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more