Parsing the Body & Handling CORS | Creating a REST API with Node.js

  Рет қаралды 248,767

Academind

Academind

Күн бұрын

Пікірлер: 237
@MrFeanaro9
@MrFeanaro9 3 жыл бұрын
I've used a lot of different youtubers, website tutorials, and even codeacademy. I'm not sure what you are doing different but it's finally actually going in! I think it's because you don't bloat the tutorial with unnecessary extra technology. And you also explain the purpose of everything you write. But this has definitely been the best tutorial on Node JS that I've watched. Thanks a lot!
@jazzbandpiano
@jazzbandpiano 4 жыл бұрын
Max you are making the most brilliant tutorials on KZbin for this stuff right now. The way you let errors hit Postman and the backend, so that we can follow along with you and prevent them ourselves, is a real lifesaver. Keep up the content!!!
@carolinenunes2937
@carolinenunes2937 2 жыл бұрын
god, it feels SO good when you're watching a tutorial video and you can simply understand everything is going on without pausing and going back, even if it's the first time I see it. What an awesome instructor, im pretty luck to have found you :)
@teawacrossman-nixom7696
@teawacrossman-nixom7696 3 жыл бұрын
been surfing the internet for an explanation on how to work with CORS for hours now, and you my good sir, was the only person who actually explained it in a comprehensive and digestible way. Also the quick and concise explanations mixed with the beautiful face make the whole learning 100% easier, Thanks man :)
@TechInterpreter
@TechInterpreter 3 жыл бұрын
This is the best, clearest, most simple explanation I've come across (and I've watched a lot of them!) Thank you for this.
@titaniumcoder477
@titaniumcoder477 4 жыл бұрын
This is a great series! I am a developer but have never created a REST API web server. This is so much fun! You are an awesome instructor! Keep up the good work!
@asifsharif2073
@asifsharif2073 6 жыл бұрын
I was waiting for this explanation for last at least 5-6 months. Nobody able to explain it to me. Seriously you did a great job ^-^
@academind
@academind 6 жыл бұрын
That's really fantastic to read, thanks a lot for sharing this awesome feedback!
@murat6018
@murat6018 2 жыл бұрын
Agreed with the comments. I've been having troubles understanding creating rest APIs and these tutos are just heaven sent!
@The_Nova_Glow
@The_Nova_Glow 5 жыл бұрын
This guy is a mad genius!!
@АлександрМерный-м1ч
@АлександрМерный-м1ч 3 жыл бұрын
Man... you are the best! Now, in 2021 this is the best course I have watched.
@ameyaghadigaonkar6630
@ameyaghadigaonkar6630 4 жыл бұрын
Solved my cors issue with your code. Great video brother. Thank you. was not able to find solution for a long time. you have great knowledge of rest api.
@yogxoth1959
@yogxoth1959 4 жыл бұрын
Best explanation of CORS that I've seen. Thank you!
@conaxliu9677
@conaxliu9677 5 жыл бұрын
Wonderful! I was looking for solution to CORS but no one else had provided this in their videos, at least I didn't find any, until I see yours. The Postman tool is also quite a handy tool that you have introduced. Thank you very much!
@roygates6328
@roygates6328 5 жыл бұрын
Great Series Max, very clear, well structured and concise tutorials \o/ without being rude to all the other tutorial producers, I often find it difficult to follow their english or accent, yours are excellent. Top Job!!!
@academind
@academind 5 жыл бұрын
Thank you Roy, happy to read that!
@SatishSingh-ep9wi
@SatishSingh-ep9wi 4 жыл бұрын
Thank good man I have facing this cors error problem from last 6th months in my every project.But after watching your video my problem has been solved. Thanks and always be making such type of content. One hint for others-- always mention app.use(cors()) above the header codes what they say in this vedio.
@markclinton7995
@markclinton7995 8 ай бұрын
If it's not MAX I don't know who else, from youtube turorials down to Udemy courses, he sure knows how to make the knowledge and info you need sink into your brain with EASE!
@nat6106
@nat6106 4 жыл бұрын
Best CORS explanation ever, thanks! 👏
@creazy2312
@creazy2312 7 жыл бұрын
I tried to use the tutorial to create a rest api for my SPA and all requests failed, just because of the Access-Control-Allow-Headers. After some hours I spent on google, I found the same solution you present in this video :D so the tutorial comes a bit to late for me but never mind - awesome and helpful tutorial like every other other :) THANKS A LOT !
@academind
@academind 7 жыл бұрын
Still great to read that the tutorial was (or well, would have been) helpful, thanks a lot for sharing this :)
@rochbajracharya3881
@rochbajracharya3881 6 жыл бұрын
How did you solve the problem of all request failing?
@VictorvictorRamos
@VictorvictorRamos 6 жыл бұрын
:(
@JustSkillGG
@JustSkillGG 4 жыл бұрын
By far the best channel on its category! Your explaining of things is so damn clean!
@ahmadhassan5680
@ahmadhassan5680 3 жыл бұрын
I really love this serious(series).
@mariolinovalencia7776
@mariolinovalencia7776 6 жыл бұрын
You are simply awesome. I love your courses on KZbin and Udemy I was having problems with CORS and spent time looking for the solution. Your video has helped me
@academind
@academind 6 жыл бұрын
Awesome to read that the video was helpful for you Mario! Thanks a lot for your support here and on Udemy!
@somebodyyouusedtoknow8600
@somebodyyouusedtoknow8600 4 жыл бұрын
Hello, amazing video. Just wanted to say that there is now an npm package called cors that you can use on your middleware to avoid cors issues.
@alexisflores5329
@alexisflores5329 4 жыл бұрын
Thanks! Just started learning more about cors and this makes it super easy
@mhasheem1305
@mhasheem1305 3 жыл бұрын
best teacher and way of teaching is excellent
@islamway_to_jannah
@islamway_to_jannah 4 жыл бұрын
best youtube channel in the planet
@mjr333
@mjr333 4 жыл бұрын
Best explanation of CORS I've seen
@phamnhans
@phamnhans 5 жыл бұрын
You are my inspiration and role model. Thank you, teacher!
@amitkumargouda1768
@amitkumargouda1768 5 жыл бұрын
This guy made me understand cors.
@ramonmurillo167
@ramonmurillo167 7 жыл бұрын
Great video Max. It will be great if you could do the next one about securing the API using tokens.
@academind
@academind 7 жыл бұрын
I will cover that, no worries - thanks for your great feedback Ramon!
@therealchrif
@therealchrif 7 жыл бұрын
Max, Please make a video about linking our API with a SPA. and thanks for all your videos
@NuubiKakku
@NuubiKakku 4 жыл бұрын
Thank you a lot! Very helpful and wholesome content!
@_the_one_1
@_the_one_1 7 жыл бұрын
Very good explanation of CORS!!!I like very much the moment when you say 9:30
@academind
@academind 7 жыл бұрын
Thanks so much, awesome to hear that!
@sayamqazi
@sayamqazi 6 жыл бұрын
6:07 you can send numbers though on the value side "price" : 12.99 this is valid
@Fernando_SC
@Fernando_SC 4 жыл бұрын
MEEEEEEN THANKS!! YOU ARE A FUCKING GENIUS, NO ONE EXPLAIN IT BETTER THAN YOU. I WAS STUCKED IN THIS F** PROBLEM FOR A WEEK, THX A LOT MEN!!!
@edgardogonzalez2812
@edgardogonzalez2812 3 жыл бұрын
That was amazing!!!!
@JaikratSinghTariyal
@JaikratSinghTariyal 6 жыл бұрын
If you are not able to call any of your API then put next(); after closing if (req.method === 'OPTIONS') {...}
@TheMaxik
@TheMaxik 5 жыл бұрын
Thaaaaaaaaaanks man!
@raynesmike
@raynesmike 5 жыл бұрын
@Jaikrat thanks man youre dope
@shikhargupta3928
@shikhargupta3928 4 жыл бұрын
This should be pinned.
@lucaspaiano8687
@lucaspaiano8687 4 жыл бұрын
thanks dude!
@joydeepbhattacharjee5305
@joydeepbhattacharjee5305 3 жыл бұрын
Thanks man u save my day ! God bless u ❤️
@johntenorio9086
@johntenorio9086 3 жыл бұрын
¡Thank you so much! Just what I needed.
@vicliur2
@vicliur2 5 жыл бұрын
THANK YOU! I had so much trouble with CORS but you saved me!
@elecktromaestimmy
@elecktromaestimmy 4 жыл бұрын
now you can just install it npm install cors
@This__is__akash
@This__is__akash 4 жыл бұрын
Already purchase React and Node js course.
@matthiasmuller7677
@matthiasmuller7677 5 жыл бұрын
Verry gut tutorial! Sänk you for se tschörman accent, makes me understand easier
@Palonchi-n1t
@Palonchi-n1t Жыл бұрын
Thanks for sharing such knowledge to us. I am so excited of watching this course. I have another question related to this lecture. I am so confused about CSP. I tried a small project to practice. actually, I used axios for my front-end, when I fetch the data, on my browser console, content security policy is blocking my localhost, I do not know how to handle with this issue. by the way, thank you very much!!!
@rhaindeathlcook
@rhaindeathlcook 4 жыл бұрын
Thank you for the clear explanation!
@FilipCodes
@FilipCodes 4 жыл бұрын
Awesome video!!
@therealchrif
@therealchrif 7 жыл бұрын
Max, Please make a video about linking this API with a SPA. and thanks for all your videos
@christopher5731
@christopher5731 5 жыл бұрын
Max you have the best videos
@academind
@academind 5 жыл бұрын
Thank you!
@tungtran7667
@tungtran7667 4 жыл бұрын
Thank you for author... This is a very good course
@skypan7786
@skypan7786 6 жыл бұрын
Hi Max, I am your big fans. I find out that in the video 13:50, It need add next() at the end of header set function, or it will keep loading if it does not go into the if statement.
@donathmm3881
@donathmm3881 5 жыл бұрын
he did it after that
@RaymondAtivie
@RaymondAtivie 7 жыл бұрын
You're a saint Max
@academind
@academind 7 жыл бұрын
Thanks so much Raymond!
@The7azem
@The7azem 6 жыл бұрын
Thanks for the great tutorial, just one notice that price can be an int in json, values in json can be either numbers or strings, only the name needs to be in text form
@andriis1917
@andriis1917 7 жыл бұрын
Great tutorial!! Thank you for what you are doing!
@academind
@academind 7 жыл бұрын
Thanks so much Andrii, makes me really happy to read that!
@arfeenmalik8331
@arfeenmalik8331 4 жыл бұрын
For anyone who was also getting errors "...undefined" in response body: You must make sure that you define all configurations BEFORE defining routes.
@evgenykhristenko4047
@evgenykhristenko4047 4 жыл бұрын
thx helped
@eshaalraani1903
@eshaalraani1903 2 жыл бұрын
i was stuck for almost 3 days, tried everything watched almost 10+ videos 🤣🤣 and the answer to my problem was in the comments, thank you so much for sharing
@israelruas948
@israelruas948 Жыл бұрын
I high recommend this tutorial.
@bidyutmahanta85
@bidyutmahanta85 4 жыл бұрын
Thank you, you solved my CORS issue. 👍
@sounak2009
@sounak2009 5 жыл бұрын
Why can't we just app.use(cors()) after installing the cors Npm package instead of manually updating the res headers?
@MS-xu1ks
@MS-xu1ks 5 жыл бұрын
I do the same, works fine.
@عبدالقادرعبدالرحمنعبدالله
@عبدالقادرعبدالرحمنعبدالله 5 жыл бұрын
I did cors the same way as done in the tutorial but failed to work. As going through comments, i came across your comment that helped me fix it. Thanks a lot.
@hazemmohamed2872
@hazemmohamed2872 5 жыл бұрын
@@عبدالقادرعبدالرحمنعبدالله The headers added in the video should fix cors errors in many browsers, but some browsers like safari requires a small tweak which the cors package handles. In my opinion, it's better to use the cors package than writing the headers yourself (which indeed do the same but handles most suituations).
@gouravgosain8733
@gouravgosain8733 6 жыл бұрын
Complete tutorial is really helpful
@sachin__ak
@sachin__ak 4 жыл бұрын
For cors now you can use ' app.use(cors()) ' after installing cors by 'npm i cors' , hope it helps :)
@Nope22119
@Nope22119 3 жыл бұрын
this didn't work for me
@sachin__ak
@sachin__ak 3 жыл бұрын
@@Nope22119 did you do npm I cors?
@Nope22119
@Nope22119 3 жыл бұрын
​@@sachin__ak yup, i solved the issue, but this wasn't it. I was passing an extra thing into the request "mode: 'cors'". after getting rid of that it worked
@sachin__ak
@sachin__ak 3 жыл бұрын
@@Nope22119 app.use(cors()) not the recommended way to use it on production, you will have write a config options, check out the docs of cors.
@barjosa31blogspot83
@barjosa31blogspot83 7 жыл бұрын
Thanks again Max! Helpful!
@academind
@academind 7 жыл бұрын
Great to read that, thanks a lot!
@Userk86288
@Userk86288 4 жыл бұрын
It worked. Thanks a lot
@alexandertarasenko3038
@alexandertarasenko3038 6 жыл бұрын
You are great and your tutorials are awesome) Thank you for doing this) I have one small question. We could also just do req.body and receive the entire object of product, right? Is it considered to be a bad practice? Thank you for the answer)
@user-xw4mu6nz4t
@user-xw4mu6nz4t 3 жыл бұрын
JSON data can include; numbers, booleans, objects, arrays and strings null (not undefined). Not *just* strings.
@neelk7445
@neelk7445 4 жыл бұрын
if anyone is having trouble with body-parser, do not use bodyParser.json() replace it with express.json() . keep req.body.productID as it is
@OXiG96
@OXiG96 10 ай бұрын
Hello forum, the noob here Why do postman give me result of "message": "Handling POST requests to /products" at 6:10 and before? I did everything identically to the author
@El_ii
@El_ii 6 жыл бұрын
Hey Guys, before using the CORS error handling function (res.header...) install it with npm install cors --save. I spended an hour to figuring out why this wasn't working. :D
@veliea5160
@veliea5160 5 жыл бұрын
if u installed the cors, u dont need all heavy duty complex function code. cors module will handle everything for u
@ИльяКарев-р9ф
@ИльяКарев-р9ф 7 жыл бұрын
Dreaming about future courses where you'll use toys to explain the client-server interactions :)
@academind
@academind 7 жыл бұрын
Haha - not a bad idea :D
@IAmUnstoppable555
@IAmUnstoppable555 6 жыл бұрын
What shortcut key combination did you pull to do the auto indentation at 11:51?
@reza0razavipour
@reza0razavipour 6 жыл бұрын
I love theses presentations from the speaker. Is the code accessible online?
@academind
@academind 6 жыл бұрын
Thank you! You can find the source code below the video if you click onto "Resources" => academind.com/learn/node-js/building-a-restful-api-with/parsing-the-body-handling-cors/
@codinginflow
@codinginflow 3 жыл бұрын
Why do you use sometimes double quotes and sometimes single quotes? Is that equivalent?
@mohammedfalih8713
@mohammedfalih8713 3 жыл бұрын
I think there is no difference
@janpawedwa4590
@janpawedwa4590 3 жыл бұрын
there is no difference, and if you use any linter, it will probably keep all your quotes consistent, when you format your code (for example on save)
@rameshrathod01
@rameshrathod01 7 жыл бұрын
Plz make video using MySQL login with passport js and SSL using nodejs
@rscottlewis1
@rscottlewis1 5 жыл бұрын
Great job. Thanks for sharing.
@academind
@academind 5 жыл бұрын
Thank you Scott :)
@sandum150
@sandum150 7 жыл бұрын
Hi Max! It's an awesome course. But could you tell what db are you going to use?
@academind
@academind 7 жыл бұрын
I'll start with MongoDB. Maybe I later also show how you could use MySQL but I'm not decided on that yet.
@sandum150
@sandum150 7 жыл бұрын
It'll be great to use some SQL db, like MySQL or PostgreSQL. There are so few tutorials with nodejs + SQL. I wait eagerly for that.
@andreyq9179
@andreyq9179 6 жыл бұрын
Thanks a lot from Russia ; )
@academind
@academind 6 жыл бұрын
Thank you Andrey, greetings from Germany :)
@PauloRodrigues2000
@PauloRodrigues2000 5 жыл бұрын
Explicação massa ! muito obrigado
@sourajitbasu3169
@sourajitbasu3169 3 жыл бұрын
bodyParser is deprecated now... Express provides parsing out of the box now for v4.16 and above
@HimanshuSingh-fh7dt
@HimanshuSingh-fh7dt 3 жыл бұрын
same, how can we resolve this problem?
@HimanshuSingh-fh7dt
@HimanshuSingh-fh7dt 3 жыл бұрын
app.use(express.json()); app.use(express.urlencoded({ extended: true })); this is working for me
@sourajitbasu3169
@sourajitbasu3169 3 жыл бұрын
@@HimanshuSingh-fh7dt exactly. This is how it recommended now.
@kilar96
@kilar96 4 жыл бұрын
Thank you very much !!
@AbhishekKumar-mq1tt
@AbhishekKumar-mq1tt 7 жыл бұрын
Thank u for this awesome video .Can you also implement front end with this .u r awesome
@academind
@academind 7 жыл бұрын
I'll probably add some frontend later in this series, yes
@chidinwaka9231
@chidinwaka9231 5 жыл бұрын
Thank you very much, it was so helpful.
@martinsmuts2557
@martinsmuts2557 7 жыл бұрын
Thanks for these awesome videos. I was wondering how do you parse the body if you do not know the schema? For example, we expected to get price and name parameters, but what if you do not know what parameters to pass if you do not have documentation?
@academind
@academind 7 жыл бұрын
If you're creating the API for yourself, you obviously know what you expect to receive and what you therefore should pass. If you create an API that's also consumed by other, you have to create a detailed documentation for sure
@martinsmuts2557
@martinsmuts2557 7 жыл бұрын
Thanks for your reply. Yes, I understand that if you create your own one then you would know what to expect and create your own documentation. Was just wondering if it is possible to retrieve all parameters in the body that are available without parsing them one-by-one? For example, you listen for all the possible available parameters in the request.
@abhihuntergamer1150
@abhihuntergamer1150 5 жыл бұрын
Thank you soo much..Very well explained
@academind
@academind 5 жыл бұрын
Happy to read that, thank YOU for your comment!
@abhihuntergamer1150
@abhihuntergamer1150 5 жыл бұрын
I was actually having trouble in connecting api to Angular 7. I was getting this error . I took your Udemy Angular course. It’s just awesome very well explained
@MohamedJamalAli
@MohamedJamalAli 6 жыл бұрын
Hi Max, in 04:26 you said that CORS is not a good way to protect our API from un desired access, so what is the best way to protect our API from un wanted access?
@jybs8476
@jybs8476 4 жыл бұрын
Couldn't we check for the OPTIONS method first so that no time is wasted on adding unnecessary headers?
@amitbhandari8347
@amitbhandari8347 6 жыл бұрын
I am lucky to get this playlist... DHANYABAD
@SweatyCubes
@SweatyCubes 6 жыл бұрын
Before adding "res.header('Access-Control-Allow-Headers', 'Content-Type');" POST Requests work. After adding it though breaks them and then logs an error saying that No Access-Control-Allow-Origin is present even though it is. Strange.
@ankurvishwakarma8731
@ankurvishwakarma8731 6 жыл бұрын
Nice tutorials sir ..!!
@yuliat5343
@yuliat5343 5 жыл бұрын
So we don't need to install cors package in order to use it the way it is presented in the video?
@qaipak1
@qaipak1 7 жыл бұрын
in 10:20 we are making another app.use(). If it gets routed to that, how does it reach the other routes? I don't quite understand that step.
@qaipak1
@qaipak1 7 жыл бұрын
I'm an impatient bitch. Nvm
@mycomputer7539
@mycomputer7539 3 жыл бұрын
Thanks a lot sir.
@harsimerkaur4792
@harsimerkaur4792 4 жыл бұрын
Can we use npm package cors?
@raghavaggarwal8644
@raghavaggarwal8644 4 жыл бұрын
Thanks for the tutorial but how to deploy the server online? I'm building a rest api for my android app so basically i want to know how to use this with android? I will need a url right?
@levisolomon9253
@levisolomon9253 4 жыл бұрын
can we use app.use(cors()); instead of writing headers for each and everything?
@CarlosRodriguez-yw9fw
@CarlosRodriguez-yw9fw 5 жыл бұрын
Hi Max! I really like your videos, are helping me with an API develop. I have a question about CORS. This API might be private, only for people who works in a company, so, maybe it will have only the company website domain on the Access-Control-Allow-Origin. But, what if in the future, it develop some mobile app that will consume this API. How to configure this CORS header that allow the mobile app to consume it? Hope you or anybody can help me with this doubt. Thanks a lot!
@KatanaHSM
@KatanaHSM 4 жыл бұрын
[HELP] Why are we returning a status response after checking for OPTIONS? I'm a little confused here!
@kobenade
@kobenade 4 жыл бұрын
Is there anywhere to do this with fetch api
@javierzetina1621
@javierzetina1621 3 жыл бұрын
Champioooooooon!!!
@arockiamkaspar2300
@arockiamkaspar2300 7 жыл бұрын
Hi MAX, great video. Why it works only on localhost:3000/ and not in any other domain like localhost:4000/. since it accepts cross origin requests.
@88noname88
@88noname88 4 жыл бұрын
UPDATE: you can use middleware. Install cors from npm and simply add middleware to app.js. Just app.use(cors())
@Nope22119
@Nope22119 3 жыл бұрын
the cors library didn't work for me
@investingthelike111
@investingthelike111 4 жыл бұрын
what do you mean by acces-control-allow-headers? can anyone explain this in more details , why do you send a header with a request?
@ashik_shanto
@ashik_shanto 3 жыл бұрын
Body parser is deprecated. What should i do?
@matejl92
@matejl92 7 жыл бұрын
Price can be of type double/decimal.
@farhantubeify
@farhantubeify 7 жыл бұрын
Nice video. But things look time consuming and too many codes. I think for API we should go for adonis or sails. Those MVCs are pretty good for people coming from other MVCs like Laravel or Ruby on Rails or Spring.... Thanks again...
@academind
@academind 7 жыл бұрын
That's the cool thing - you got all these great options :)
@G0YoX
@G0YoX 5 жыл бұрын
Very very thanks!!!
@mdjahidulislam9205
@mdjahidulislam9205 4 жыл бұрын
Hi . urgent help.. Cors is not working with multer,form-data. I can't upload photo.
@Phakeme-Fakazi
@Phakeme-Fakazi 4 жыл бұрын
thanks like always.
MongoDB and Mongoose | Creating a REST API with Node.js
36:03
Academind
Рет қаралды 442 М.
CORS express.js tutorial | Cross-Origin Resource Sharing in Node
21:39
Sigma Kid Mistake #funny #sigma
00:17
CRAZY GREAPA
Рет қаралды 30 МЛН
BAYGUYSTAN | 1 СЕРИЯ | bayGUYS
36:55
bayGUYS
Рет қаралды 1,9 МЛН
Planning & First Steps | Creating a REST API with Node.js
14:41
Academind
Рет қаралды 436 М.
Dependency Injection, The Best Pattern
13:16
CodeAesthetic
Рет қаралды 917 М.
You might not need useEffect() ...
21:45
Academind
Рет қаралды 179 М.
AI Is Making You An Illiterate Programmer
27:22
ThePrimeTime
Рет қаралды 277 М.
Mongoose Validation | Creating a REST API with Node.js
18:33
Academind
Рет қаралды 141 М.
10 common mistakes with the Next.js App Router
20:37
Vercel
Рет қаралды 242 М.
What is REST API?
15:41
Piyush Garg
Рет қаралды 167 М.
I tried 8 different Postgres ORMs
9:46
Beyond Fireship
Рет қаралды 449 М.
Node.js API Authentication With JWT
23:01
Traversy Media
Рет қаралды 560 М.
Sigma Kid Mistake #funny #sigma
00:17
CRAZY GREAPA
Рет қаралды 30 МЛН