1.1.2 • Published 5 years ago

pexels-api-wrapper v1.1.2

Weekly downloads
113
License
ISC
Repository
github
Last release
5 years ago

Pexels API

A simple wrapper to use the Pexels API. Please refer to the API docs to undestand the inputs and expected results.

Installation

Install the package

$ cd /path/to/app
$ npm install --save pexels-api-wrapper

Usage

//In NodeJS App

//Require Wrapper Library
const PexelsAPI = require('pexels-api-wrapper');

//Create Client instance by passing in API key
var pexelsClient = new PexelsAPI("<API_KEY>");

//Search API
pexelsClient.search("food", 10, 1)
    .then(function(result){
        console.log(result);
    }).
    catch(function(e){
        console.err(e);
    });

//Get Popular Photos
pexelsClient.getPopularPhotos(10, 1)
    .then(function(result){
        console.log(result);
    }).
    catch(function(e){
        console.err(e);
    });

//Get Curated Photos
pexelsClient.getCuratedPhotos(10, 1)
    .then(function(result){
        console.log(result);
    }).
    catch(function(e){
        console.err(e);
    });

//Get Photo by ID
pexelsClient.getPhoto(123456)
    .then(function(result){
        console.log(result);
    }).
    catch(function(e){
        console.err(e);
    });

//Search Video API
pexelsClient.searchVideos("food", 10, 1)
    .then(function(result){
        console.log(result);
    }).
    catch(function(e){
        console.err(e);
    });

//Get Popular Videos
pexelsClient.getPopularVideos(10, 1)
    .then(function(result){
        console.log(result);
    }).
    catch(function(e){
        console.err(e);
    });

API

Search

Promise factory to interact with Pexels Search API

ParamTypeDescription
querystringThe search term to query the API with
per_pagenumberThe number of results to return per page (Defaults to 10)
pagenumberThe page number to return (Defaults to 1)
PexelsAPI.search(query, per_page, page);

Popular

Promise factory to interact with Pexels Popular Photos API

ParamTypeDescription
per_pagenumberThe number of results to return per page (Defaults to 10)
pagenumberThe page number to return (Defaults to 1)
PexelsAPI.getPopularPhotos(per_page, page);

Curated

Promise factory to interact with Pexels Curated Photos API

ParamTypeDescription
per_pagenumberThe number of results to return per page (Defaults to 10)
pagenumberThe page number to return (Defaults to 1)
PexelsAPI.getCuratedPhotos(per_page, page);

Photo

Promise factory to fetch a single photo from Pexels Photos API

ParamTypeDescription
idnumberThe ID of the photo
PexelsAPI.getPhoto(id);

Search Videos

Promise factory to interact with Pexels Videos API

ParamTypeDescription
querystringThe search term to query the API with
per_pagenumberThe number of results to return per page (Defaults to 10)
pagenumberThe page number to return (Defaults to 1)
min_widthnumberThe minimum width in pixels of the returned videos. (optional)
max_widthnumberThe maximum width in pixels of the returned videos. (optional)
min_durationnumberThe minimum duration in seconds of the returned videos. (optional)
max_durationnumberThe maximum duration in seconds of the returned videos. (optional)
PexelsAPI.searchVideos(query, per_page, page, min_width, max_width, min_duration, max_duration);

Popular Videos

Promise factory to interact with Pexels Popular Videos API

ParamTypeDescription
per_pagenumberThe number of results to return per page (Defaults to 10)
pagenumberThe page number to return (Defaults to 1)
min_widthnumberThe minimum width in pixels of the returned videos. (optional)
max_widthnumberThe maximum width in pixels of the returned videos. (optional)
min_durationnumberThe minimum duration in seconds of the returned videos. (optional)
max_durationnumberThe maximum duration in seconds of the returned videos. (optional)
PexelsAPI.getPopularVideos(per_page, page, min_width, max_width, min_duration, max_duration);

Changelog

VersionChanges
v1.0.8First published version
v1.1.1Extended library to accommodate new APIs: getCuratedPhotos getPhoto searchVideos getPopularVideos, Base URL uses HTTPS by default
v1.1.2Extended library to accommodate new parameters for width and duration

Contribution Ideas

  1. Change the string parameter (API Key) currently used while initializing the client to support an options object as well. This object can contain the apiKey and useHttps as options to start with which can drive whether the client uses HTTP or HTTPS. This will also create a structure which can allow future extensibility by adding keys to the options object.
  2. Make this library browser friendly. Refactor code to stop using node-fetch and use an isomorphic version instead. The current version, as it stands, is not optimal to be used on the browser.

Acknowledgements

Thanks, Pexels for creating a great platform for great images. Always rooting for you.

I'd like to thank all the folks taking the time out to keep this library in sync with the Pexels API. Power to you!

Shout out to: @fcrespo82, @jeffski and jbuchmann-coosto for their pull requests which has kept the library in sync with the changes in the API.

1.1.2

5 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.9

8 years ago

1.0.8

8 years ago

1.0.7

8 years ago

1.0.6

8 years ago

1.0.5

8 years ago

1.0.4

8 years ago

1.0.3

8 years ago

1.0.0

8 years ago