Nextjs Tutorial #3 - API Routes

preview_player
Показать описание
In this part we implement axios cancel requests, refactor our application a bit and make use of nextjs api routes.

💖 Follow & Subscribe
Рекомендации по теме
Комментарии
Автор

I've watched this a few times and I find it odd or I just might not understand the works of Axios, but would it not make most sense to post the values to the api route instead of using get two times?

saratiko
Автор

Hi,

Thank you for the great tutorial.

I have a couple of questions if you don't mind:

At around 09:46 you mention that the reason that we get the "cannot read property 'data' of undefined" is that the request inside the try block gets canceled and therefore we get undefined as the value of res. My question is why didn't we get this error before moving the code inside the try-catch block? We were running the same code and canceling the request even without the try catch block correct? Then why didn't we get the same error then?

Also, at around 17:20 when you modify the code to have the call to Github repo serverside, I noticed that you are using axiosGetCancelable when calling Next api whereas in the api you are using a regular axios call to Github. So the question is why does this work? I mean from what I understand requests made to Next api/backend are cancelable but not the requests that are actually made from that api to Github's. Does the cancelable property of our requests to the backend somehow carries over to requests from the backend to Github's endpoint?

I'd appreciate any insight.

Once again thank you for this tutorial series.

mehdihadjikhani
join shbcf.ru