Skip to content

Instantly share code, notes, and snippets.

@krazyjakee
Created March 28, 2019 09:16
Show Gist options
  • Select an option

  • Save krazyjakee/b16838e91befbad7f6f393f6c2bf73a9 to your computer and use it in GitHub Desktop.

Select an option

Save krazyjakee/b16838e91befbad7f6f393f6c2bf73a9 to your computer and use it in GitHub Desktop.

Revisions

  1. krazyjakee created this gist Mar 28, 2019.
    6 changes: 6 additions & 0 deletions clientSideUsage.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    import axios from 'axios';

    axios.get('/popular')
    .then(res => {
    console.log(res.data);
    });
    14 changes: 14 additions & 0 deletions igdb.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    import apicalypse from 'apicalypse';

    const defaultConfig = {
    method: 'POST',
    baseURL: 'https://api-v3.igdb.com',
    headers: {
    'user-key': API_KEY,
    accept: 'application/json',
    },
    responseType: 'json',
    timeout: 30000,
    }

    export default (config) => apicalypse(config || defaultConfig);
    17 changes: 17 additions & 0 deletions serverSideUsage.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    // Usage on the serverside
    import igdb from './igdb';

    // An example express route
    server.get(
    '/popular',
    async (req, res) => {
    const response = await igdb()
    .fields("name, popularity")
    .where('popularity != null & themes != (42) & version_parent = null')
    .sort('popularity', 'desc')
    .limit(20)
    .request('/games');

    res.json(response.data);
    }
    );