REST API in Node.js

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.

Running on Browser

  • To get the emission of carbon by amount of electricity used in a country:
* 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```



### Running the app locally 
 ```bash
 $ git clone https://github.com/mukulsaini/REST_API.git
 $ npm install 
$ npm start

Open this link in the browser

Running Tests

 $ npm test

CURL Example

$ 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"