Built a rest Api in Node.js by leveraging Node.js
Back-End API
- https://myrestfulapplication.herokuapp.com/api/users
- Please Use POSTMAN for Testing Purpose !!
- Authenticate Client First
- Username : divyanshu
- Password : xyz
- A JWT will be generated and used for subsequent request from Client to server !
- You can register as well no need to rely on username : divyanshu !!
- This Api compares results returned by ‘Haversine’ formula and MongoDB Geospatial Indexes and Queries feature.
- when a location is given and we need to fetch all the nearby points within a radius.
- Used JSON web tokens for token-based user authentication.
- Used ‘Haversine’ formula to calculate distance between given (Latitude,longitude) pairs.
- This Api compares results returned by ‘Haversine’ formula and MongoDB Geospatial Indexes and Queries feature.
app.post('/post_location',callback.post_location);
app.get('/get_location',callback.get_location);
app.get('/',callback.basic_route);
app.post('/register',callback.register_user);
app.get('/users',callback.get_users);
app.post('/get_using_self',callback.get_using_self);
app.post('/get_using_self',callback.get_using_mongodb
-
Clone or download the repo. into any fresh temporary folder.
-
Cd into that root folder you just cloned locally.
-
Open terminal in the current folder and to install all dependencies type
npm install
- Now typing
nodemon server.js
- will start a server !
- MLab's MongoDB hosting platform is the fastest growing cloud Database-as-a-Service in the world. Get started with a free database and expert support.
- NPM is the default package manager for the JavaScript runtime environment Node.js.
- For dependencies refer Package.json.
- Postman extension can be used for testing !
- Supercharge your API workflow with Postman! Build, test, and document your APIs faster.
- You can now fire up postman and then perform several operations on the REST API.
-
Create your branch:
git checkout -b my-new-feature
-
Commit your changes:
git commit -m 'Add some feature'
-
Push to the branch:
git push origin my-new-feature
-
Send a Pull Request
-
Enjoy!
Examples
- GET Request to URL http://localhost:4000/api/get_location (with access token!)
- POST Request to URL https://myrestfulapplication.herokuapp.com/api/register (User Registration !)
Comparison between Haversine Formula v/s Mongodb Geospatial
- Sample Data via Postman
{"radius":"10","coordinates":[38.8,-77.0]} Data Format - [lat,long]
- POST Request to URL localhost:4000/api/get_using_self
- POST Request to URL localhost:4000/api/get_using_mongodb