Advertisement
Advertisement

More Related Content

Advertisement

Build RESTful API Using Express JS

  1. Building API With Node JS and Express Cakra Danu Sedayu / Full Stack Developer
  2. @dilo_medan groups/DevCMedan CAKRA DANU SEDAYU Fullstack Developer mashara.id cakra.ds@gmail.com @cakrads
  3. 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
  4. Ingredients download and install download and install npm -i express npm -i mongoose npm install -g nodemon npm install body-parser download and install
  5. Basic Node JS Simple Word : Server-side Javascript !(Simple World): High-performance Network Applications Framework
  6. CORE ENGINE ● JS V8 Engine by Google ● Non-Blocking I/O ● Event Loop
  7. Theory Non- Blocking IO
  8. Traditional I/O - Synchronous - Wait for each operation to complete, after that executes next operation - Step by Step executions
  9. - Asynchronous - Never waits each operation to complete, executes all at one time. - Callbacks used to handle result Non-blocking I/O
  10. What can we do with NODE JS ● HTTP Server ● TCP Server ● DNS Server ● Static File Server ● Web Chat Application (GTalk) ● Desktop GUI Application
  11. Who uses Node.JS (in production) 0 1 source : https://github.com/nodejs/node-v0.x-archive/wiki/Projects,-Applications,-and-Companies-Using-Node
  12. Rahasia Disesuaikan untuk nama perusahaan Versi 1.0 Basic Core Engine Teory Non-Blocking IO How To Use? Review Node JS
  13. How to USE ?
  14. Concept ● Use Modules ● One or more modules libraries are called PACKAES ● To Install PACKAGES, we use NPM (Node Package Manager)
  15. Let’s Practice
  16. - Install Node JS (engine and NPM) - chec installation in terminal or command promt - $ node -v - $nom -v Installation
  17. Try install Moment https://momentjs.com/
  18. $ npm i node-modules $ node server.js Make HTTP Server Result:
  19. API
  20. 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
  21. Modern Website image source and modified : https://farm1.staticflickr.com/907/41762807282_03cbff0e4f_b.jpg
  22. image source and modified : https://farm1.staticflickr.com/907/41762807282_03cbff0e4f_b.jpg Modern Architecture Use API
  23. RESTful API ● API - Application Programming Interface ● REST API - REpresentational State Transfer ● RESTful sudah Pasti REST ● RESTful use HTTP verbs
  24. HTTP Verbs HTTP VERB CRUD POST CREATE GET READ PUT UPDATE DELETE DELETE
  25. 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
  26. Rahasia Disesuaikan untuk nama perusahaan Versi 1.0 Traditional Website Modern Website RESTful API HTTP Verbs Review API
  27. BUILD API USING EXPRESS
  28. 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”: “”}
  29. Express JS
  30. 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 :
  31. CREATE - METHOD POST Default : Use body-parser : read more about body-parser in : https://www.npmjs.com/package/body-parser
  32. READ - METHOD GET
  33. UPDATE - METHOD PUT
  34. DELETE - METHOD DELETE
  35. ● No SQL Database ● Mongoose (Library)
  36. - Create Schema in Model All data will select by email email = id
  37. - Create in Controller
  38. - Read in Controller All data will select by email email = id
  39. - Update in Controller All data will select by email email = id
  40. - Delete in Controller All data will select by email email = id
  41. Terima kasih.

Editor's Notes

  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
Advertisement