Building a REST API using Node JS & Express

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi everyone in this video we will create a rest API using node.js okay our task could be to create a new task okay to delete to get research and to update an existing task okay so let's get started to create these apis so I have opened an API name folder so in this folder we will create our node.js up first we should install node.js I have already installed loot.js if you didn't install so you should install that first of all let's select no version OK version 16. so now let's create a folder here by the name of backend and oh sorry this should be folder after getting this folder so now let's come to the command prompt here we will write we'll go to the backend directory the first thing is that we should install the express okay expresses uh framework for node.js okay to write the backend code using Express you will use that npm install Express uh oh sorry first thing is just to initialize APM npm in it hyphen y okay by using this command it will initialize npm with our bucket folder it will create a package.json folder yeah fine it has created so now let's install uh Express yeah that is installing yeah the express has installed okay so now let's create a file by the name of server.jsr index.js whatever name you assigned to that we will create that so now we will write our code here the first thing is just to export import our Express working so far that website is equal to require Express okay after that we will use the express we will initialize the express so further to let's write up is equal to express and also we will change our data to the Json format so far that we will use app.use Express .json now our server will listen on the port so let's further to write a lesson it will listen our port number for example 8081 and we will print a message with that sneak yes so our server is listening at this port we can run on this port okay so now let's write the apis so to write the apis first we will get the data so for that let's create a list of movies ID would be one because [Music] ABC for example and date would be for example 23 23 okay let's create one another object this is the second one yeah we have these two objects so now let's first of all um display this okay for that we will like it means that to get data to write API for getting the data so for that we will write up dot gate here we will write our URL it is for example the Slash and this route and this route we will access and after that we will have two parameters here a callback function first one will be the request the second response and here we will just get our data return on our data so for that I will write result.json and we will return the movies okay it will determine the movies for us so now let's create API for post later we will check them so for the poster for example movie here again we will do parameters request and first of all we will get the videos so to get the videos comes to movie is equal to request.body and after that we will push that to our movies object so for that I will write movies dot push object and send the HTTP response result dot sent object added okay so now let's write um for searching okay for search we will light again the app dot get our route would be movie slash ID okay this is an ID we will skip the records request in response and here again we first we will get the ID from our this route so to get the ID will be light concept is equal to request dot forums dot ID it will get the ID for us so now we will filter and we will get the one we if we would like okay the one the object that we want comes to movie is equal to oh conspirin or movies dot filter and it F dot ID was equal to equal to with the ID that we have okay it will just filter the the record that we need okay based on that high research will assign it to this so we can result that Json print that movie and if you would like to delete a record so for that we would like after delete our route would be to be slash ID again we will just copy this write it here we will get first of all the ID then we will just change this one okay not just filter those record which is not the ID is not same with that okay all the card will be assigned to this moving object without the one that we want okay that idb standard that idea okay so yeah we did it so now let's run our server so the light node server.js yeah it's listening okay it is listening a port number but this port 8081 so let's come here and here we will light localhost our Port is running an 80 81 if the records has created for us it is called this API okay for us the git API this is DC but the first and delete we cannot check that in the browser because we need Postman to check that in that software but right now we cannot check that okay because here by default the browser is git calling like it we can check this one also okay to get the searchable movie so let's write like this slash movie slash two for example it will be just the second card for us okay the secondary card has start for us so it was all about the apis creating apis key in node.js if you would like to get the data from database simply just use the queries and to get the data from from database and here we created just an object for testing purpose so I hope this video was helpful for you if you like this video so please subscribe our YouTube channel and thanks for watching
Info
Channel: Code With Yousaf
Views: 3,331
Rating: undefined out of 5
Keywords: build a nodejs app, building a restful api, rest api using nodejs, build a nodejs api, build a rest api, how to build api using node js, building rest api in node js, how to build restful api using node.js, api using node js, building rest api with node.js, restful api using nodejs, restful api using nodejs and mongodb, building rest api with mysql, post request using postman in hindi, lets build a node rest api, build a rest api with node, rest api tutorial, rest api
Id: akIQ0Dxs0Nk
Channel Id: undefined
Length: 9min 13sec (553 seconds)
Published: Sun Mar 12 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.