/node-pexels

Node client for https://www.pexels.com API

Primary LanguageTypeScriptMIT LicenseMIT

node-pexels

Node client for https://www.pexels.com API. Typescript definitions included.

Build Status Coverage Status

Simple api client for Pexels powered by got package.

Check out Pexels API for API usage rules and key request.

Requirements

Node 8+

Changelog

v 0.0.4

Added retrieving single photo method (#1)

v 0.0.3

Some fixes in inner logic and interfaces. Added methods args validation. Some fixes in doc.

v 0.0.2

Some fixes in schema and ts definitions.

v 0.0.1

Hello, world! First version of package.

Usage

const Client = require('node-pexels').Client;

const client = new Client('your-api-key');

client.search('people', 5, 1)
    .then((results) => {
        // Do something with results
        console.log(results);
    })
    .catch((error) => {
        // Something bad happened
        console.error(error);
    });

Docs

Client

constructor(apiKey: string)

Creates new API client instance.

search(query: string, perPage?: number, page?: number): Promise<IPexelsResponse>

Search request by provided query.

photo(id: number): Promise<IPexelsImage>;

Search photo by provided id.

popular(perPage?: number, page?: number): Promise<IPexelsResponse>

Popular photos request.

IPexelsResponse, IPexelsImage

Responses from pexels api.

You can find schemas here and response example on the Pexels API page.

FAQ

Does client use http or https?

Client use https. You can use http (if you really want to) by modifying endpoint property of Client function.

I want to have Buffer object instead of image url, what should i do?

Current version of module can't do this (hope to implement it in some future releases), you should do it in your own code.