A simple rest api example for calculating carbon footrpints from various sources.
Authentication has been done using passport.js localapikey on every request.
app.route('/api/authenticate')
.post(
passport.authenticate('localapikey', { failureRedirect: '/api/unauthorized', failureFlash: true }),
function(req, res) {
res.json({ message: "Authenticated" });
});Mocha and Chai is used to carry out the test cases.
THe app is deployed on Heroku.
- To get the emission of carbon by amount of electricity used in a country:
https://node-restapi.herokuapp.com/api/electricity?apikey=asdasjsdgfjkjhg&use=2.4&country=UK
- To get the emission of carbon by amount of natural gas used in a country :
https://node-restapi.herokuapp.com/api/naturalGas?apikey=asdasjsdgfjkjhg&use=2.4&country=UK
$ git clone https://github.com/mukulsaini/REST_API.git$ npm install $ npm startOpen this link in the browser
Running Tests
$ npm test$ curl --get -v -d "apikey=asdasjsdgfjkjhg" "https://node-restapi.herokuapp.com/api/electricity?use=2.4&country=UK" $ curl --get -v -d "apikey=asdasjsdgfjkjhg" "https://node-restapi.herokuapp.com/api/naturalGas?apikey=asdasjsdgfjkjhg&use=2.4&country=UK"