4 releases
0.2.1 | Jul 7, 2019 |
---|---|
0.1.2 | May 3, 2019 |
0.1.1 | May 3, 2019 |
0.1.0 | May 3, 2019 |
#494 in #documentation
33KB
87 lines
Pexels
A Rust wrapper for Pexels API.
- Documentation – https://docs.rs/pexels/
- Crates.io – https://crates.io/crates/pexels
- Repository – https://github.com/andraantariksa/pexels
License
The application is available as open source under the terms of the MIT License.
lib.rs
:
The pexels
crate provides API wrapper for Pexels. It based on Pexels API Documentation.
To get the API key, you have request the access from Request API Access – Pexels.
This library are depends on serde-json crate to handle the result, thus you have to read the documentation serde_json - Rust, especially serde_json::Value - Rust.
Setup
Add this line to your Cargo.toml
file, below [dependencies]
pexels = "*"
and this to your crate root file e.g main.rs
:
extern crate pexels;
Done! Now you can use this API wrapper.
Example
This example shows how to get the list of mountains photos.
extern crate pexels;
fn main() {
let pexels_api_client = pexels::Pexels::new("YOUR_API_KEY".to_owned());
pexels_api_client.photo_search("mountains".to_string(), 15, 1);
}
and you can run it using cargo run
! Simply as that.
Random photo
If you want to get a random photo, you can use the curated_photo
function and set per_page to 1 and page to a random number between 1 and 1000 to get a beautiful random photo. You can do the same with popular searches if you want to get a random photo with a specific topic.
Image formats
- original - The size of the original image is given with the attributes width and height. *large - This image has a maximum width of 940px and a maximum height of 650px. It has the aspect ratio of the original image.
- large2x - This image has a maximum width of 1880px and a maximum height of 1300px. It has the aspect ratio of the original image.
- medium - This image has a height of 350px and a flexible width. It has the aspect ratio of the original image.
- small - This image has a height of 130px and a flexible width. It has the aspect ratio of the original image.
- portrait This image has a width of 800px and a height of 1200px.
- landscape - This image has a width of 1200px and height of 627px.
- tiny - This image has a width of 280px and height of 200px.
Dependencies
~22MB
~452K SLoC