Giter Site home page Giter Site logo

giphy-api's Introduction

giphy-api

Build Status NPM version

Simple to use Node.js module for the giphy.com API that supports promises and callbacks. All search parameters and endpoints can be found on the Giphy API documentation.

Giphy logo

Installation

npm install giphy-api --save

Requiring

// Require with custom API key
var giphy = require('giphy-api')('API KEY HERE');
// Require with the public beta key
var giphy = require('giphy-api')();

Initialization Options

var giphy = require('giphy-api')({
    ...
});
  • https {Boolean} - Whether to utilize HTTPS library for requests or HTTP. Defaults to HTTP.
  • timeout {Number} - Maximum timeout of an API request. Defaults to 30 seconds.
  • apiKey {String} - Giphy API key. Defaults to API beta key

Search all Giphy GIFs for a word or phrase. Supported parameters:

  • q - search query term or phrase
  • limit - (optional) number of results to return, maximum 100. Default 25.
  • offset - (optional) results offset, defaults to 0.
  • rating - limit results to those rated (y,g, pg, pg-13 or r).
  • fmt - (optional) return results in html or json format (useful for viewing responses as GIFs to debug/test)
// Search with a plain string using callback
giphy.search('pokemon', function(err, res) {
    // Res contains gif data!
});

// Search with options using promise
giphy.search('pokemon').then(function(res) {
    // Res contains gif data!
});
// Search with options using callback
giphy.search({
    q: 'pokemon',
    rating: 'g'
}, function(err, res) {
    // Res contains gif data!
});

Search all Giphy gifs for a single Id or an array of Id's

//Search with a single Id using callback
giphy.id('feqkVgjJpYtjy', function(err, res) {

});

//Search with a single Id using promise
giphy.id('feqkVgjJpYtjy').then(function(res) {

});
// Search with an array of Id's
giphy.id([
    'feqkVgjJpYtjy',
    '7rzbxdu0ZEXLy'
], function(err, res) {

});

Experimental search endpoint for gif dialects. Supported parameters:

  • s - term or phrase to translate into a GIF
  • rating - limit results to those rated (y,g, pg, pg-13 or r).
  • fmt - (optional) return results in html or json format (useful for viewing responses as GIFs to debug/test)
// Translate search with a plain string using callback
giphy.translate('superman', function(err, res) {

});

// Translate search with a plain string using promise
giphy.translate('superman').then(function(res) {

});
// Translate search with options
giphy.translate({
    s: 'superman',
    rating: 'g',
    fmt: 'html'
}, function(err, res) {

});

Random gif(s) filtered by tag. Supported parameters:

  • tag - the GIF tag to limit randomness by
  • rating - limit results to those rated (y,g, pg, pg-13 or r).
  • fmt - (optional) return results in html or json format (useful for viewing responses as GIFs to debug/test)
// Random gif by tag using callback
giphy.random('superman', function(err, res) {

});

// Random gif by tag using promise
giphy.random('superman').then(function(res) {

});
// Random gif with options
giphy.random({
    tag: 'superman',
    rating: 'g',
    fmt: 'json'
}, function(err, res) {

});

Trending gifs on The Hot 100 list

  • limit (optional) limits the number of results returned. By default returns 25 results.
  • rating - limit results to those rated (y,g, pg, pg-13 or r).
  • fmt - (optional) return results in html or json format (useful for viewing responses as GIFs to debug/test)
// Trending Hot 100 gifs using callback
giphy.trending(function(err, res) {

});

// Trending Hot 100 gifs using promise
giphy.trending().then(function(res) {

});
// Trending Hot 100 gifs with options
giphy.trending({
    limit: 2,
    rating: 'g',
    fmt: 'json'
}, function(err, res) {

});

Animated stickers are gifs with transparent backgrounds. All giphy-api functions support stickers except id, which is not a supported Giphy sticker endpoint. In order to use the sticker API instead of the gif API, simply pass the api property to a giphy-api function.

// Sticker search using callback
giphy.search({
    api: 'stickers',
    q: 'funny'
}, function(err, res) {

});

// Sticker search using promise
giphy.search({
    api: 'stickers',
    q: 'funny'
}).then(res) {

});

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.