Part 11: Setup Product Routes and get all the products and single products by id Api

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
welcome back um in this video I'm going to show you the route of the products okay so we have already finished our user route and and made aware authentication and in this user route we have like getting the profine data with the with the with the token and update the profine data uh using the token as well with the put meth that so right now I'm going to show you the product route okay the UCD dogs so we create another F under the under the route I'm sorry so I need to uh turn off my notification so um so here uh under the route we have created prodest GS and yeah so let's do it um I will say for the products uh we have we will use the APR as well EB SS a because we need to use a route I and require and express so we have import Express after that we can say uh prodct UT rout equal uh Express do router okay this router oops so uh we have our router so after that we will get all the products from our uh database where is our database and browse collection under the collection we have product list okay we will get all these products from our uh product route so I will say product route do get with the get M that and then slash so that's it and after slash uh we will use the is ense um error Handler so we will import the package con as YNC H and D and er equal require a Express Ence Handler okay so we will use this and we will import here and inside this one one uh we will say s YNC asense and another bracket request and IQ outside of this bracket we will say um K bracket AR function key so uh inside this uh we will create uh we will get okay we will get all the product const so getting the all the products we don't need the key because we will show these all the products at the homepage without the user is login or not okay so uh I will I will show you uh like this so in our um so yeah so as you see so in here um so as you see uh in here so we have like homepage if the user is not login or um no all user or guest user can access the kinds of products that's why we don't need a key for this okay that's why I don't use I don't use any other um any other I mean I don't use the the a middleware a okay we don't need the product so we will directly F the other the product so that's why I will say con VDS equal a weight I wait uh I will find from product model so we have model here uh we have product model so from the product model I will get all these data their name is products okay that's why we need to uh import this products so in here con V UCD product equ require um from uh do/ model SL products okay so uh we have imported our product model so I will say find I will get all that's why I don't need to import any other um parameter here so I just need to do like this and we will get our uh product so respon will s Jon format with the products so our product is now sent back as a respond Json data so let me go and check in our in our um Postman so so I will delete all um okay what is that login save and user register save change profile say change uh save change okay so for this um user profile so I will duplicate duplicate and then I will say um all p r o d du all products with the get method user uh a s would use DS but right now if we call uh it will get error because we haven't set up in our index.js fine for this route okay we'll go and set up so let me open index.js our our main server file and also we need to rent our server okay so I will run mbn rent server so it will rent our server in a port 3,000 so like this we need to create another route and this is the V as products products but we need to import our products don't forget to export module your product module okay so after that we can uh we can use this module later so module do exports equal uh products route so our product R modu is ready to um use in our index. GS file so I will go and import anywhere anywhere you prefer okay so I will create here const uh P product route equ I require uh SL R SL prods um I will use the D um the same uh like this I don't want to use sing or so everything will be the same stretcher Okay cool so after that um this comment is very messy here okay so products after that I can use product rout yd product routes so cool so this product route has been module has been imported in our index. gsy and we have um our product route as well so when we call this uh main route we will get all the products and the product route because we have bestl here okay so I will fetch as you see we have got our products array list here so let me show you uh one and two so these products has been uh return back as a respond to some data here okay cool so now I I will trying to fetch single products so for this one I need to create another route uh P the UCD BR route do get as well so in this here I will first uh the product by the ID So like um two door after that ID so it mean uh we were we will send the the the the dynamic ID anything okay ID will be accept SL id prodct id after that we will use the as Handler as well and there is Handler bracket we will see Ence so inside the Ence I mean after Ence we will have another bracket and request and respond so after that we use ER function key the same thing and we will say con BD product this time one product that's why we don't need s so here list of product that's why we add s okay so we will say await and then product do find find ID okay so we will find with the request uh par. ID okay we will brand the ID from parameter URL okay after that we will get our product so we will have if condition if this product is Exist by the ID we will do um the text S we will do another another response so this respon will be 44 not found state with the 44 error BR not found okay so if it we found we will WR Jon uh respond so I do rjon this products okay this product will be sent back so I will format so everything is fine so we go back and after that we need to pass the product ID okay here like product ID and then if I sent one product has been found like this so here as I show you um I will show you yeah yeah if it um if it is use a click on one product here uh here as you see if user click like single product okay so we got uh product with the product ID as you see here the the the URL look at Host product SL and the the ID of the products so SLE product page like this so we we were uh we will use this API later on with the re um us user interface like this okay so cool uh yeah that's it after uh we have set um product route we will set up another one called order so user can make a order and insert the order model so that's it um the ABM will be finished after we have seted order route so we will go to our Reet project after we have finished our API thank you guys see you in the next video
Info
Channel: Goo Coding
Views: 68
Rating: undefined out of 5
Keywords: expressjs, jwt, mongoosedb, nodejs, paypal, react, tailwindcss
Id: I1_xMa6I9b4
Channel Id: undefined
Length: 11min 0sec (660 seconds)
Published: Sun Oct 01 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.