diff --git a/README.md b/README.md index cd1fe0f..174e540 100644 --- a/README.md +++ b/README.md @@ -14,9 +14,10 @@ The intent is to simplify the request process by handling the tedious logic. It' * [Installation](#installation) * [Usage](#usage) +* [Starter Guide](#starter-guide) +* [Using express js](#using-express-js) * [API Details](#api-details) * [Examples](#examples) -* [Starter Guide](#starter-guide) * [Test](#test) * [Issues](#issues) @@ -45,6 +46,9 @@ let ebay = new eBay({ Check out the [Starter Guide](https://pajaydev.github.io/ebay-node-api) documentation with examples to get started. +## Using Express js +You can consume these ebay node api's using [Express](https://expressjs.com/). You can checkout the sample app [here](). + ## API details ### Without Auth flow diff --git a/demo/node-express/README.md b/demo/node-express/README.md new file mode 100644 index 0000000..dc31a4f --- /dev/null +++ b/demo/node-express/README.md @@ -0,0 +1,14 @@ +# Express js starter kit +Consume `ebay-node-api` api's using node express js. + + +## Run the example + +```shell +npm install +# start the server. +npm start +``` + +## Authentication. +Replace your client id here diff --git a/demo/node-express/index.html b/demo/node-express/index.html new file mode 100644 index 0000000..5b443c2 --- /dev/null +++ b/demo/node-express/index.html @@ -0,0 +1,40 @@ + + + + + + Ebay node api demo + + + +

Ebay node api playground

+ + +

Items:

+
+ + + \ No newline at end of file diff --git a/demo/node-express/package.json b/demo/node-express/package.json new file mode 100644 index 0000000..39eec6d --- /dev/null +++ b/demo/node-express/package.json @@ -0,0 +1,13 @@ +{ + "name": "ebay-node-api-example", + "version": "1.0.0", + "main": "server.js", + "license": "MIT", + "dependencies": { + "ebay-node-api": "^2.8.7", + "express": "^4.17.1" + }, + "scripts": { + "start" : "node server.js" + } +} diff --git a/demo/node-express/server.js b/demo/node-express/server.js new file mode 100644 index 0000000..86b7e9f --- /dev/null +++ b/demo/node-express/server.js @@ -0,0 +1,36 @@ +'use strict'; +const express = require('express'); +const path = require('path'); +const Ebay = require('ebay-node-api'); +const app = express(); +const port = 3000; + +const ebay = new Ebay({ + clientID: "----Client id----" +}); + +// load index.html +app.get('/', (req, res) => res.sendFile(path.join(__dirname + '/index.html'))); + +// create a route to search items in eBay. +app.use('/search', function(req, res){ + const queryParam = req.query; + // call the ebay api + ebay.findItemsByKeywords({ + keywords: queryParam.keyword, + sortOrder: 'PricePlusShippingLowest', //https://developer.ebay.com/devzone/finding/callref/extra/fndcmpltditms.rqst.srtordr.html + Condition: 3000, + SoldItemsOnly: false, + affiliate: { + networkId: 9, + trackingId: 1234567890 + } + }).then((data) => { + return res.status(200).send(data); + }, (error) => { + return res.status(404).send(data); + }); +}); + +// listen to the port. +app.listen(port, () => console.log(`Example app listening at http://localhost:${port}`)); \ No newline at end of file