Top Banner
CREATE REST API IN NODEJS WITH EXPRESS FRAMEWORK AND MONGOOSE
24

Create Rest API in Nodejs

Jan 08, 2017

Download

Software

Irfan Maulana
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Create Rest API in Nodejs

CREATE REST API IN NODEJS

WITH EXPRESS FRAMEWORK AND MONGOOSE

Page 2: Create Rest API in Nodejs

ABOUT ME

Name : Irfan Maulana

Work in : PT Global Digital Niaga (Blibli.com)

Position : Software Development Engineer

+ JavaScript Enthusiast

+ Specialize in Web Front-End

+ New knowledge addicted

Page 3: Create Rest API in Nodejs

WHAT IS REST API• REST : Representational State Transfer• was defined by Roy Thomas Fielding in his 2000 PhD dissertation

"Architectural Styles and the Design of Network-based Software Architectures".

• It relies on a stateless, client-server, cacheable communications protocol -- and in virtually all cases, the HTTP protocol is used. (http://rest.elkstein.org/)

Page 4: Create Rest API in Nodejs

REST CONSTRAINTS• Client–server• Stateless• Cacheable• Uniform Interface

Page 5: Create Rest API in Nodejs

REST METHODS• GET• POST• PUT• DELETE

Page 6: Create Rest API in Nodejs

NODEJS• JavaScript runtime built on Chrome's V8 JavaScript engine. Node.js uses an

event-driven, non-blocking I/O model that makes it lightweight and efficient.

Page 7: Create Rest API in Nodejs

EXPRESS• is a minimal and flexible Node.js web application framework that provides a

robust set of features for web and mobile applications.

Page 8: Create Rest API in Nodejs

MONGOOSE• Elegant mongo DB object modeling for node.js

Page 9: Create Rest API in Nodejs

<LETS-START-CODE/>

Page 10: Create Rest API in Nodejs

SET UP DEPENDENCIES

Page 11: Create Rest API in Nodejs

BASIC REST IN EXPRESS• Require express framework

• Create app

• Our very first API

• And check it

Page 12: Create Rest API in Nodejs

CONNECT MONGODB WITH MONGOOSE• Require mongoose

• Create connection

• You can add handler state

Page 13: Create Rest API in Nodejs

CREATE MODEL IN MONGOOSE• Require connection

• Create schema

• Create model

Page 14: Create Rest API in Nodejs

USING MODEL AS ORM• Require model

• Save data using ORM

Page 15: Create Rest API in Nodejs

EXPRESS ROUTE (1)• Require express and get router instance

• Require model for ORM usage

• Create route for path / with GET method to get all data in database

Page 16: Create Rest API in Nodejs

EXPRESS ROUTE (2)• Create route for path / with POST method to insert new data

Page 17: Create Rest API in Nodejs

EXPRESS ROUTE (3)• Create route for path /:id with GET method to get data by ID

Page 18: Create Rest API in Nodejs

EXPRESS ROUTE (4)• Create route for path /:id with PUT method to update existing data with new data by ID

Page 19: Create Rest API in Nodejs

EXPRESS ROUTE (5)• Create route for path /:id with DELETE method to remove data by ID

• Create root path for all your API

Page 20: Create Rest API in Nodejs

TEST IN POSTMAN (1)

Page 21: Create Rest API in Nodejs

TEST IN POSTMAN (2)

Page 22: Create Rest API in Nodejs

TEST IN POSTMAN (3)

Page 23: Create Rest API in Nodejs

SOURCE CODE REPOSITORY

https://github.com/mazipan/nodejs-simple-restfull-with-express

Page 24: Create Rest API in Nodejs

THANK YOU

Linkedin : https://id.linkedin.com/in/irfanmaulanamazipan

Github : https://github.com/mazipan

Email : [email protected]

Mobile : 0857-8123-8798