Skip to content

Instantly share code, notes, and snippets.

@clarle
Created October 24, 2015 16:06
Show Gist options
  • Select an option

  • Save clarle/b8a096311e33cbda8c61 to your computer and use it in GitHub Desktop.

Select an option

Save clarle/b8a096311e33cbda8c61 to your computer and use it in GitHub Desktop.

Revisions

  1. clarle created this gist Oct 24, 2015.
    30 changes: 30 additions & 0 deletions app.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    var _ = require('lodash'),
    express = require('express'),
    request = require('request'),
    app = express();

    var API_KEY = '1Kfdqvy6wHmvJ4LDyAVOl7saCBoKHcSb';

    app.get('/products/:id', function(req, res) {
    var ourData = {
    age_group: '0-1 years old',
    tags: ['math', 'problem solving', 'counting']
    };

    var id = req.params.id;
    request.get('http://api.target.com/items/v3/' + id, {
    qs: {
    id_type: 'dpci',
    key: API_KEY
    },
    json: true
    }, function(err, response, body) {
    var targetItems = _.get(body, 'product_composite_response.items');
    ourData.urls = targetItems.map(function(item) {
    return item.data_page_link;
    });
    res.json(ourData);
    });
    });
    app.listen(5000);
    console.log('App running on port 5000');