Contact Us

Contact Us



Pleas confirm by checkbox


Uncategorized

Ways to create REST API's

Author_img
By Mayank Agrawal December 14, 2017

For your first application lets assume that you are building an application for blogs and you want to create  REST apis which can be consume by frontend/mobile application .

    • API should create blogs into database.
    • API should update blogs into database.
    • API should delete blogs from database.
    • API should find and fetch a blog using any existing blog id from database.

Prerequisite

  1. mongodb is installed and server is running on default port.
  2. Node 6.9.0 is installed.
  3. IDE like vscode is available to you.
  4. Rest client like postman,curl for testing.

Installation

  1. git clone https://github.com/ratneshsinghparihar/nodedata-demo-sample.git
  2. cd nodedata-demo-sample/Demo-Sample
  3. npm install

Code changes

  • Add a model blogmodel.ts inside models folder.
  • Add a repository blogmodelrepository.ts inside repositories folder.

[gist]6beea0b1a959769ff529d53203a9bc6d[/gist]

  • Model with @document tell the system to create a document inside blogs collection.
  • repository with blog name will create all necessary rest end points.

Testing

  1. npm start
  2. Post a JSON {“name”: “testBlog”} to http://localhost:9999/data/blogs
  3. Hit the api to get data(http://localhost:9999/data/blogs)
  4. Hit the api with put method http://localhost:9999/data/blogs/{{blogId}} with body {“name”: “testBlog1”}
  5. Hit the api with delete method http://localhost:9999/data/blogs/{{blogId}}

Conclusion

Now you can see how creating rest apis is super easy with node-data. If you want to know more check out the our github
 
https://github.com/ratneshsinghparihar/Node-Data

Or visit our main page

https://nodedataio.azurewebsites.net/

Related posts
VPC Sharing Using AWS RAM (Resource Access Manager)
Uncategorized

VPC Sharing Using AWS RAM (Resource Access Manager)

By mynkgrwl22 June 18, 2019
Reduce App size with On Demand Resources
Uncategorized

Reduce App size with On Demand Resources

By mynkgrwl22 May 29, 2019
iMessage Stickers and Apps
Uncategorized

iMessage Stickers and Apps

By mynkgrwl22 May 27, 2019
What is UX Writing?
Uncategorized

What is UX Writing?

By mynkgrwl22 April 08, 2019
AWS ECS (Amazon Elastic Container Service )
Uncategorized

AWS ECS (Amazon Elastic Container Service )

By mynkgrwl22 March 26, 2019
Scala code analysis and coverage report on Sonarqube using SBT
Uncategorized

Scala code analysis and coverage report on Sonarqube using SBT

By mynkgrwl22 March 19, 2019
Introduction to Akka Streams
Uncategorized

Introduction to Akka Streams

By mynkgrwl22 March 08, 2019
Decentralized Applications - Utilizing the Power of Blockchain Technology
Uncategorized

Decentralized Applications - Utilizing the Power of Blockchain Technology

By mynkgrwl22 March 05, 2019
App Store Connect API To Automate TestFlight Workflow
Uncategorized

App Store Connect API To Automate TestFlight Workflow

By mynkgrwl22 February 28, 2019
Using Custom Metrics for CloudWatch Monitoring
Uncategorized

Using Custom Metrics for CloudWatch Monitoring

By mynkgrwl22 February 06, 2019

Stay updated

Get the latest creative news from Fubiz about art, design and pop-culture.