SlideShare uma empresa Scribd logo
1 de 41
Building API
With Node JS and Express
Cakra Danu Sedayu / Full Stack Developer
@dilo_medan groups/DevCMedan
CAKRA DANU SEDAYU
Fullstack Developer
mashara.id
cakra.ds@gmail.com
@cakrads
Rahasia Disesuaikan untuk nama perusahaan Versi 1.0
Basic
Core Engine
Theory Non-Blocking IO
How To Use?
Traditional Website
Modern Website
RESTful API
HTTP Verbs
Design Endpoints
Express JS
Practice
Daftar Isi
Node JS API Show Time
Ingredients
download and install
download and install
npm -i express
npm -i mongoose
npm install -g nodemon
npm install body-parser
download and install
Basic Node JS
Simple Word :
Server-side Javascript
!(Simple World):
High-performance
Network Applications Framework
CORE ENGINE
● JS V8 Engine by Google
● Non-Blocking I/O
● Event Loop
Theory Non-
Blocking IO
Traditional I/O
- Synchronous
- Wait for each operation to complete, after that executes next
operation
- Step by Step executions
- Asynchronous
- Never waits each operation to complete, executes all at one
time.
- Callbacks used to handle result
Non-blocking I/O
What can we do with
NODE JS
● HTTP Server
● TCP Server
● DNS Server
● Static File Server
● Web Chat Application (GTalk)
● Desktop GUI Application
Who uses Node.JS (in production)
0
1
source : https://github.com/nodejs/node-v0.x-archive/wiki/Projects,-Applications,-and-Companies-Using-Node
Rahasia Disesuaikan untuk nama perusahaan Versi 1.0
Basic
Core Engine
Teory Non-Blocking IO
How To Use?
Review
Node JS
How
to USE ?
Concept
● Use Modules
● One or more modules libraries are
called PACKAES
● To Install PACKAGES, we use NPM
(Node Package Manager)
Let’s
Practice
- Install Node JS (engine and NPM)
- chec installation in terminal or command promt
- $ node -v
- $nom -v
Installation
Try install Moment
https://momentjs.com/
$ npm i node-modules
$ node server.js
Make HTTP Server
Result:
API
Traditional Website
image source and modified : https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/00/56/73/3225.NoAPIArchitecture.PNG
Modern Website
image source and modified : https://farm1.staticflickr.com/907/41762807282_03cbff0e4f_b.jpg
image source and modified : https://farm1.staticflickr.com/907/41762807282_03cbff0e4f_b.jpg
Modern Architecture Use API
RESTful API
● API - Application Programming Interface
● REST API - REpresentational State Transfer
● RESTful sudah Pasti REST
● RESTful use HTTP verbs
HTTP Verbs
HTTP VERB CRUD
POST CREATE
GET READ
PUT UPDATE
DELETE DELETE
RESTful API VS Normal API
table : users
CRUD URL Normal URL RESTful
Create users/create users
Read users/read/id users/id
Update users/update/id users/id
Delete users/delete/id users/id
Rahasia Disesuaikan untuk nama perusahaan Versi 1.0
Traditional Website
Modern Website
RESTful API
HTTP Verbs
Review
API
BUILD API
USING EXPRESS
Design Endpoints
Method Endpoint Description Data
GET api/users List of users [{}, {}, {}]
GET api/users/:id View a users {}
POST api/users Create a new users {“msg”: “”}
PUT api/users/:id Update a user {“msg”: “”}
DELETE api/users/:id Delete a user {“msg”: “”}
Express JS
Structure
api-node-express
models
users.js
controllers
users.js
routes.js
server.js
api-node-express
api
users
usersController.js
usersModel.js
Type 1 : Type 2 :
CREATE - METHOD POST
Default : Use body-parser :
read more about body-parser in :
https://www.npmjs.com/package/body-parser
READ - METHOD GET
UPDATE - METHOD PUT
DELETE - METHOD DELETE
● No SQL Database
● Mongoose (Library)
- Create Schema in Model
All data will select by email
email = id
- Create in Controller
- Read in Controller
All data will select by email
email = id
- Update in Controller
All data will select by email
email = id
- Delete in Controller
All data will select by email
email = id
Terima kasih.

Mais conteúdo relacionado

Mais procurados

Mais procurados (20)

Express JS
Express JSExpress JS
Express JS
 
Spring Framework - Core
Spring Framework - CoreSpring Framework - Core
Spring Framework - Core
 
Express js
Express jsExpress js
Express js
 
Rest api with node js and express
Rest api with node js and expressRest api with node js and express
Rest api with node js and express
 
Introduction to Node js
Introduction to Node jsIntroduction to Node js
Introduction to Node js
 
Spring boot Introduction
Spring boot IntroductionSpring boot Introduction
Spring boot Introduction
 
Expressjs
ExpressjsExpressjs
Expressjs
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.js
 
Nodejs presentation
Nodejs presentationNodejs presentation
Nodejs presentation
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
Introduction à spring boot
Introduction à spring bootIntroduction à spring boot
Introduction à spring boot
 
Nodejs Explained with Examples
Nodejs Explained with ExamplesNodejs Explained with Examples
Nodejs Explained with Examples
 
Introduction to ReactJS
Introduction to ReactJSIntroduction to ReactJS
Introduction to ReactJS
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Angular 2.0 forms
Angular 2.0 formsAngular 2.0 forms
Angular 2.0 forms
 
Spring boot introduction
Spring boot introductionSpring boot introduction
Spring boot introduction
 
Node js Modules and Event Emitters
Node js Modules and Event EmittersNode js Modules and Event Emitters
Node js Modules and Event Emitters
 
Node js Introduction
Node js IntroductionNode js Introduction
Node js Introduction
 
Spring boot - an introduction
Spring boot - an introductionSpring boot - an introduction
Spring boot - an introduction
 

Semelhante a Build RESTful API Using Express JS

An Overview of Node.js
An Overview of Node.jsAn Overview of Node.js
An Overview of Node.js
Ayush Mishra
 
Day in a life of a node.js developer
Day in a life of a node.js developerDay in a life of a node.js developer
Day in a life of a node.js developer
Edureka!
 

Semelhante a Build RESTful API Using Express JS (20)

Building Applications With the MEAN Stack
Building Applications With the MEAN StackBuilding Applications With the MEAN Stack
Building Applications With the MEAN Stack
 
Complete MVC on NodeJS
Complete MVC on NodeJSComplete MVC on NodeJS
Complete MVC on NodeJS
 
JSFest 2019: Technology agnostic microservices at SPA frontend
JSFest 2019: Technology agnostic microservices at SPA frontendJSFest 2019: Technology agnostic microservices at SPA frontend
JSFest 2019: Technology agnostic microservices at SPA frontend
 
Introduction to Node.JS
Introduction to Node.JSIntroduction to Node.JS
Introduction to Node.JS
 
How NOT to get lost in the current JavaScript landscape
How NOT to get lost in the current JavaScript landscapeHow NOT to get lost in the current JavaScript landscape
How NOT to get lost in the current JavaScript landscape
 
An Overview of Node.js
An Overview of Node.jsAn Overview of Node.js
An Overview of Node.js
 
ASP .Net Core SPA Templates
ASP .Net Core SPA TemplatesASP .Net Core SPA Templates
ASP .Net Core SPA Templates
 
How to convert your Full Trust Solutions to the SharePoint Framework (SPFx)
How to convert your Full Trust Solutions to the SharePoint Framework (SPFx)How to convert your Full Trust Solutions to the SharePoint Framework (SPFx)
How to convert your Full Trust Solutions to the SharePoint Framework (SPFx)
 
Top Reasons to Use Node.JS Development for Your Next Project
Top Reasons to Use Node.JS Development for Your Next ProjectTop Reasons to Use Node.JS Development for Your Next Project
Top Reasons to Use Node.JS Development for Your Next Project
 
StrongLoop Overview
StrongLoop OverviewStrongLoop Overview
StrongLoop Overview
 
JS Fest 2019/Autumn. Влад Федосов. Technology agnostic microservices at SPA f...
JS Fest 2019/Autumn. Влад Федосов. Technology agnostic microservices at SPA f...JS Fest 2019/Autumn. Влад Федосов. Technology agnostic microservices at SPA f...
JS Fest 2019/Autumn. Влад Федосов. Technology agnostic microservices at SPA f...
 
How to convert your Full Trust Solutions to the SharePoint Framework (SPFx)
How to convert your Full Trust Solutions to the SharePoint Framework (SPFx)How to convert your Full Trust Solutions to the SharePoint Framework (SPFx)
How to convert your Full Trust Solutions to the SharePoint Framework (SPFx)
 
Seattle StrongLoop Node.js Workshop
Seattle StrongLoop Node.js WorkshopSeattle StrongLoop Node.js Workshop
Seattle StrongLoop Node.js Workshop
 
Nodejs Intro - Part2 Introduction to Web Applications
Nodejs Intro - Part2 Introduction to Web ApplicationsNodejs Intro - Part2 Introduction to Web Applications
Nodejs Intro - Part2 Introduction to Web Applications
 
An Overview on Nuxt.js
An Overview on Nuxt.jsAn Overview on Nuxt.js
An Overview on Nuxt.js
 
Getting Started with ASP.NET Core 1.0 (formerly ASP.NET 5)
Getting Started with ASP.NET Core 1.0 (formerly ASP.NET 5)Getting Started with ASP.NET Core 1.0 (formerly ASP.NET 5)
Getting Started with ASP.NET Core 1.0 (formerly ASP.NET 5)
 
Day in a life of a node.js developer
Day in a life of a node.js developerDay in a life of a node.js developer
Day in a life of a node.js developer
 
Day In A Life Of A Node.js Developer
Day In A Life Of A Node.js DeveloperDay In A Life Of A Node.js Developer
Day In A Life Of A Node.js Developer
 
Node, express & sails
Node, express & sailsNode, express & sails
Node, express & sails
 
Intro to Sails.js
Intro to Sails.jsIntro to Sails.js
Intro to Sails.js
 

Último

introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
VishalKumarJha10
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 

Último (20)

%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
LEVEL 5 - SESSION 1 2023 (1).pptx - PDF 123456
LEVEL 5   - SESSION 1 2023 (1).pptx - PDF 123456LEVEL 5   - SESSION 1 2023 (1).pptx - PDF 123456
LEVEL 5 - SESSION 1 2023 (1).pptx - PDF 123456
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
ManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide DeckManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide Deck
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 

Build RESTful API Using Express JS

Notas do Editor

  1. REST ( Representational State Transfer) itu arsitektur sebuah software, sedangkan RESTful API itu merupakan salah satu model implementasi dari web service. RESTful API merupakan implementasi dari API. RESTful itu protokol/aturan untuk melakukan REST. Jadi RESTful itu udah pasti REST, namun REST belum tentu bisa disebut RESTful.
  2. REST ( Representational State Transfer) itu arsitektur sebuah software, sedangkan RESTful API itu merupakan salah satu model implementasi dari web service. RESTful API merupakan implementasi dari API. RESTful itu protokol/aturan untuk melakukan REST. Jadi RESTful itu udah pasti REST, namun REST belum tentu bisa disebut RESTful.
  3. Create Folder api-node-express npm install express --save check in package.json Try make Server: console.log(`Server running at http://${hostname}:${port}/`); Ada Pertanyaan??
  4. Express memberikan kita flexiblelitas untuk membuat API/routing kita bisa bentuk MVC bisa 1 folder aja atau 1 file di server.js tetepi kita anggap proyek kita ini adalah proyek besar, jadi kita membutuhkan structure yang baik