REST API
so this is the second part to my previous post 'Understanding REST api',in this part we'll make a small REST - API in node JS. so without further ado let's start making your first ever API
TOOLS
- install node js (https://nodejs.org)
- install vs code (editor)
- install POSTMAN (for testing routes)
Steps
- create a folder
- initialize the folder with
npm init -y
- open the folder in vscode
- type ctrl+shift+` in your keyboard to open integrated terminal
- we'll be using expressjs for writing api
- so in terminal type
npm install express uuid
- uuid will help us to create a RFC random id
- in
package.json
go to scripts and replace tests with
"scripts":{ "start":"node app.js" }
LET'S start
create a file called app.js
in your root folder
inside app.js
write the following code
all of our routes are stores in folder called routes/routes.js
inside routes.js
write the following code
how to check whether request working or not?
open the postman , if you want a get request ,select GET from a dropdown , and type endpoint in url section
you can checkout the code at : https://github.com/WhoAdarshPandya/rest_for_beginners
in upcoming blogs , we'll cover how to deploy a complete rest api on heroku :)
Top comments (0)