Тёмный

Next.js Route Handlers | API Routes in Nextjs 13 

Dave Gray
Подписаться 338 тыс.
Просмотров 44 тыс.
50% 1

Опубликовано:

 

15 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 109   
@saman6199
@saman6199 Год назад
I've been following this Next JS course in last 8 days and honestly this is the first time I could grasp most of the concept in such a short time, it's all because of your through explanation. You have my gratitude and I really appreciate your effort and hard work Dave 🔥
@DaveGrayTeachesCode
@DaveGrayTeachesCode Год назад
Glad I could help!
@karanchilwal1259
@karanchilwal1259 Год назад
Hey Dave, I want to express my gratitude for providing such valuable and high-quality videos and explaining topics in a clear and concise manner. I've been following your Next.js series , and I'm wondering how many more videos you plan to release in this series. Thank you for sharing your expertise and knowledge with us!
@DaveGrayTeachesCode
@DaveGrayTeachesCode Год назад
Thank you! I never know how many videos. I just follow the content until I feel like it is complete.
@treyjapan
@treyjapan Год назад
@@DaveGrayTeachesCode Hello Dave, thank you for creating this immensely useful Next.js series (and of course all of your other coding videos)! I was wondering, with Next.js 13.3 released mere days ago ( adding File-Based Metadata API, Dynamic Open Graph Images, Static Export for App Router, Parallel Routes and Interception), would you consider covering these updates in future videos? That would be super helpful :)
@bushbuddyplatypus
@bushbuddyplatypus 7 месяцев назад
A little progress everyday. great advice. I'm coming from Angular and have learnt React and Next over the past few months. It has been tough but getting there one hour at a time.
@AliMaher212
@AliMaher212 Год назад
Thx Dave. Your tutorials makes NextJS docs more easy to understand
@DaveGrayTeachesCode
@DaveGrayTeachesCode Год назад
Glad to hear that!
@zombiefacesupreme
@zombiefacesupreme Год назад
Great video! I was ready to nitpick about whether or not you should put your handlers in a specific folder and you tip toed around that confusion perfectly. The biggest re-factor in this whole thing is change req.body to req.json() on every dang route lol.
@markuscwatson
@markuscwatson Год назад
Hey Dave, thanks for this. I’d love it if your next video would show how to store data in a database using something like Prisma. Thanks.
@DaveGrayTeachesCode
@DaveGrayTeachesCode Год назад
I may do a video on that after this series covers all of the fundamentals.
@0xPanda1
@0xPanda1 Год назад
A better alternative would be using drizzle orm
@vsakaria
@vsakaria Год назад
Next js doc have updated the example to api dir. Great work Dave
@ardenttechie
@ardenttechie Год назад
Thank you for the tutorial. I have been searching for this solution for a while now but I can sleep well tonight.
@DaveGrayTeachesCode
@DaveGrayTeachesCode Год назад
Glad I could help
@jalalhitech
@jalalhitech 11 месяцев назад
Thank you so much for the video ❤
@dopetag
@dopetag Год назад
Thank you Dave. It's a really helpful api routes overview!
@DaveGrayTeachesCode
@DaveGrayTeachesCode Год назад
You are welcome!
@user-ck7ts3ml1g
@user-ck7ts3ml1g 11 месяцев назад
Hi! I got this error when I clicked on Submit in the feedback form - ------------ [Error] Failed to load resource: the server responded with a status of 404 (Not Found) (thank-you, line 0) [Error] WebSocket connection to 'ws://localhost:3000/_next/webpack-hmr' failed: WebSocket is closed due to suspension.. What does it mean and how can I resolve it? Edit - I could see the inputs in the terminal of my VS Code. Though the above problem still persisted.
@fluntimes
@fluntimes 10 месяцев назад
I've looked around and this is the best video on the new way of using routes in Next. Brilliant
@sdfsfsfd437
@sdfsfsfd437 Год назад
Awesome videos! Many thanks for these Nextjs13 info! 💯💛
@DaveGrayTeachesCode
@DaveGrayTeachesCode Год назад
You're welcome!
@walassi834
@walassi834 21 день назад
Hi, @Dave Gray! How are you doing? I'm loving the next.js content. I saw that you have some many courses, but you also had a link to ZTM. Do you recommend buying ZTM after seeing you content?
@k303k
@k303k 9 месяцев назад
Thanks a lot Dave! I 've learned a lot from your series
@MOJICA7257
@MOJICA7257 Год назад
Thanks Dave! Cheers🎉🎉🎉
@DaveGrayTeachesCode
@DaveGrayTeachesCode Год назад
Welcome!
@maak8524
@maak8524 Год назад
Enjoying this Next.js series. Just wanted to mention that the link to the next video in this series that shows up in the final seconds of the video is pointing to 9. Middleware instead of 8. REST API. Caused a little confusion but thought I'd mention it.
@patite3103
@patite3103 Год назад
Thank you for this series! I would appreciate, if you could some videos on the different new features of version 13.3. Thank you!
@DaveGrayTeachesCode
@DaveGrayTeachesCode Год назад
13.3 was just released yesterday. I'll be going over some as the series continues.
@Grishopping
@Grishopping Год назад
As always thank you very much Dave for your fantastic videos, regards Jose Grillo
@DaveGrayTeachesCode
@DaveGrayTeachesCode Год назад
Thank you, Jose!
@webncyber
@webncyber 4 месяца назад
Hi Dave thank you for this great tutorial! I had a general API question to get your input for. I have a headless CMS API and my nextjs calls it to get data, but the way it gets data is by calling the api route in the nextjs, so my library method calls the internal API routes and my internal API calls the CMS API. I wonder if this is a bad design in this case maybe I dont need to use the internal API route and just call the CMS API directly you think? Because I am no able to use cache in this way and it only works with no-store value in fetch method. Please let me know what do you think thank you!
@ruuma1074
@ruuma1074 Год назад
im kinda new with nextJS but I wondering where are the datas goes? because I didnt see any configuration to the database. hopefully isnt a silly question XD
@VincentFulco
@VincentFulco 9 месяцев назад
Hey Gang- Not sure when it changed, but the api (i.e. echo, etc.) now needs to use the following to get around a #405 error--> "export async function GET" instead of "export default function GET"
@iamjaivanth4099
@iamjaivanth4099 11 месяцев назад
Api route is not working or is not included in build folder, I want to deploy the app, while deploy api are not working
@FAYZs
@FAYZs 8 месяцев назад
you are a great instructor . Thank you
@youneshenni5417
@youneshenni5417 Год назад
amazing tutorial. You have a gift for teaching.
@HigherStudyAspirant
@HigherStudyAspirant 9 месяцев назад
Thanks for detailed explanation. but I have one confusion, what is the need of route handler if we have separate backend suppose nest js. Then calling api endpoints from server component and then from route handler as like same thing calling twice. I am just using next for frontEnd to take advantage of SSR, SEO etc.
@DaveGrayTeachesCode
@DaveGrayTeachesCode 9 месяцев назад
You shouldn't use route handlers for server components. Use them with client components to hide API keys or other secrets.
@tunaralyarzada
@tunaralyarzada Год назад
Hey Dave, Thanks for this tutorial at first! But, there is an issue I have been struggling with. The issue is that, when i wanna access to my session obejct information here writing useServerSession(authOption), it returns null! Note that, if i send request through search area of my browser, it return session object. but unfortunately when i send request through my code like axios or fetch, it returns null! Do u know the solution of it?
@DaveGrayTeachesCode
@DaveGrayTeachesCode Год назад
Definitely not a topic for this series covering the fundamentals. I have many requests for covering auth though and plan to in the future.
@tunaralyarzada
@tunaralyarzada Год назад
@@DaveGrayTeachesCode I just wanted ur help, it is related to api rootes.
@jeffery614
@jeffery614 Год назад
Clear and easily understand ! thank you!
@arielkashani6390
@arielkashani6390 Год назад
I realy appreciate you for the way you teach thats very thorough. Could you make a full app with next.js using also cookies and auth?
@DaveGrayTeachesCode
@DaveGrayTeachesCode Год назад
That might be a good follow-up!
@annssarr
@annssarr Год назад
Very good explanation. Better than some paid courses. I want to ask whether you we have some project in nextJS 13.2, if so could you please share the git repo, so me and others can see the which architecture you are using.
@DaveGrayTeachesCode
@DaveGrayTeachesCode Год назад
The previous two lessons in this series built small projects. Another coming soon, too.
@Mahmoud_A999
@Mahmoud_A999 8 месяцев назад
Your content is very powerful and useful , plz what is vs code theme you use? and can you make a tutorial on prisma and mongodb here!?
@abdulrehmanbaber2104
@abdulrehmanbaber2104 11 месяцев назад
i though async functions cannot be used inside "use client"....?
@joaobarradas8894
@joaobarradas8894 6 месяцев назад
I believe only Route Handlers are allowed (client side calls)
@HamidRazaButt
@HamidRazaButt Год назад
Thanks dave for this brilliant work🎉🎉❤
@DaveGrayTeachesCode
@DaveGrayTeachesCode Год назад
You're welcome!
@peterkawenjakalyemenya8083
@peterkawenjakalyemenya8083 Год назад
thanks dave. however i would like to know how we can impliment both Post and get in the same route.js file
@DaveGrayTeachesCode
@DaveGrayTeachesCode Год назад
The next video in this series does just that.
@7doors847
@7doors847 Год назад
Friday tutssssss! Tu tu tu 🎶 🔥
@DaveGrayTeachesCode
@DaveGrayTeachesCode Год назад
Right on!
@user-wh8py6xb2t
@user-wh8py6xb2t Год назад
Hey Dave, you're great, and thanks a lot for providing us such awesome tutorials. I have got a question, what if I want to send files to the API route or backend? In a react app I've done this using new formData() API in the client side, and in the backend to get the formdata I also used multer package. Now, I'm wondering how do I achieve the same thing in the next Js?
@alsherifkhalaf7385
@alsherifkhalaf7385 Год назад
It is great new approach . but i tried to use this new way to upload file via api route , but I failed : just simple file upload : const headers = { 'Content-Type': 'multipart/form-data', }; const response = await fetch('/api/job', { method: 'POST', body: form, headers }) route.tsx : import { NextResponse } from 'next/server'; export const config = { api : { bodyParser : false, } } export async function POST(request: Request) { const res = await request.formData() return NextResponse.json({ res }) } the error : error - DOMException [AbortError]: Error: Multipart: Boundary not found I searched but can't find any solution for use formData through api
@camembertsucreausucre3440
@camembertsucreausucre3440 Год назад
Hi dave, what a great tutorial, do you know how i can set an api key ?
@shayanhdry6224
@shayanhdry6224 11 месяцев назад
Hello Dave , I want to ask what is the state of ReactJS now ? so there is no more just React JS ? all the react project migrate to Next js ? next question what happens to state management ? with out state management what happens to interactivity of the application ?im not seeing anyone use state management ! Would mind please explaining that ?
@DaveGrayTeachesCode
@DaveGrayTeachesCode 11 месяцев назад
Good questions - Next.js is highly recommended. Even by the React docs but there are also other options. You can still write client-side React with Next.js. However, depending on the app, it may be preferred to take advantage of server components, cached requests and database connections.
@Waraji258
@Waraji258 Год назад
Hello Everyone! Thank you much for the video, really good guide!! But I have a question, when you created the Fetch for the API you had to declare the full API URL, localhost:3000/api/... When I deploy my app on Vercel, will I have to change the URL before sending it? But they have a dynamic url for branches. How can i keep track of the BASE URL to update the call for the API ? Before the APP_DIR you just needed to call '/api/example', why the new version needs the full base URL ??
@DaveGrayTeachesCode
@DaveGrayTeachesCode Год назад
I used the full URL with thunder client. It is not a component. If the component is part of your app, and you are fetching from the API, then you can just use a path.
@patite3103
@patite3103 Год назад
Would it be possible to take the same example but use server actions instead to understand the differences? Thank you in advance!
@DaveGrayTeachesCode
@DaveGrayTeachesCode Год назад
I do have a video on server actions: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-BmUsDuLO598.html
@patite3103
@patite3103 Год назад
@@DaveGrayTeachesCode the idea is to apply server actions to this example to understand the difference to this video. Thank you.
@stonecomstock
@stonecomstock Год назад
Thanks Dave! SO being able to create API routes and back end logic with Next, would there still be any need for express JS? Or would I be able to essentially create an entire full stack app all with next JS, and still be able to connect to databases and such with only next? What would be some drawbacks of using only next JS or an example of a situation where I might still want to use express? Thanks again Dave
@DaveGrayTeachesCode
@DaveGrayTeachesCode Год назад
Yes, you can create a full backend REST API with Next.js. It comes down to preference, need, and what you are comfortable with. Next.js is still growing and changing while Express with Node.js is well-established. For example, applying CORS handling in Next requires writing a wrapper function where Express just needs. app.use() and the import of cors.
@TravinskiyVladislav
@TravinskiyVladislav Год назад
Thank you, Dave
@DaveGrayTeachesCode
@DaveGrayTeachesCode Год назад
You're welcome!
@elemental097
@elemental097 Год назад
hello, is there a way to get params in route handlers using [items] folder?
@DaveGrayTeachesCode
@DaveGrayTeachesCode Год назад
You can use params. In the follow up video, I give this a small discussion.
@kuroisan2698
@kuroisan2698 Год назад
The most confusing thing I found in the new api directory is the request type isn't http.IncomingMessage instead it is Request so I couldn't find any way to make a file upload since all file parsersI know (formidable, multer, busboy ...) work only with request that has IncomingMessage type do you have any idea to implement file upload ?
@DaveGrayTeachesCode
@DaveGrayTeachesCode Год назад
I'll look into this.
@al-doori2392
@al-doori2392 Год назад
Hello Dave, thanks for the video. I am really looking forward to implementing refresh and access token (JWT) using interceptors like you did in thr React series. I have a project I am working with in NextJs it is real painful I didn’t find any way till now how to implement it with my own backend (c#) and recommendations ?😭
@DaveGrayTeachesCode
@DaveGrayTeachesCode Год назад
I may cover auth - or various auth approaches as there is more than one - in a more advanced video after this series covers all of the fundamentals.
@patite3103
@patite3103 Год назад
Would it be possible to do a tutorial with the same content but using the server actions for the form (version 13.4). Thank you
@DaveGrayTeachesCode
@DaveGrayTeachesCode Год назад
I'm sure I can in the future.
@EAbdoAhmedSayed
@EAbdoAhmedSayed Год назад
After react and redux toolkit Is it better to start learning typescript or next ?
@DaveGrayTeachesCode
@DaveGrayTeachesCode Год назад
I recommend TypeScript first although it is not required. Most use TypeScript with Next, and I do in this series.
@alsherifkhalaf7385
@alsherifkhalaf7385 Год назад
Could you add to this form a simple pdf upload file to another backend ?
@koopa9815
@koopa9815 Год назад
THANK YOU!!!!
@DaveGrayTeachesCode
@DaveGrayTeachesCode Год назад
Welcome!
@LukeOh-c4e
@LukeOh-c4e Год назад
Goodjob dave:)
@DaveGrayTeachesCode
@DaveGrayTeachesCode Год назад
Thank you!
@avgspacelover
@avgspacelover Год назад
dave can you make tutorials on designing REST, GRPC AND GRAPHQL API's
@DaveGrayTeachesCode
@DaveGrayTeachesCode Год назад
Yes, I want to - good requests!
@over1498
@over1498 Год назад
Vercel is on a mission to make as many tutorials as obsolete as possible as quickly as they can. src folder is not even an option anymore (in --experimental-app at least) Can't wait til they deprecate the app folder next week. God help anyone trying to learn the most current version of Next!
@DaveGrayTeachesCode
@DaveGrayTeachesCode Год назад
It can feel like that. I do use the src folder with the latest experimental app features. That has not been removed. It is an option while creating the project.
@dopetag
@dopetag Год назад
Indeed it is an option. And I tend to keep src folder just to keep the things more clear. Another thing is that they don't have a app/api/hello/route.ts for the default setup. I had to create it form scratch.
@yusifhasanov2504
@yusifhasanov2504 Год назад
do you think videos about tRPC
@DaveGrayTeachesCode
@DaveGrayTeachesCode Год назад
Yes, I plan to do that.
@erfanpaya3100
@erfanpaya3100 Год назад
Hello. I had a question whether this training is for full stack or frontend.
@DaveGrayTeachesCode
@DaveGrayTeachesCode Год назад
Please go to lesson 1 in this series and confirm you have completed the prerequisites before starting it. At this point, you should know that Next.js is full stack.
@faf1469
@faf1469 Год назад
Sir How many more videos left of this amazing nextjs 13 course?
@DaveGrayTeachesCode
@DaveGrayTeachesCode Год назад
I don't know as I never plan them out. I just follow the content. There's a few left.
@faf1469
@faf1469 Год назад
@@DaveGrayTeachesCode 👍
@eucheckout7
@eucheckout7 Год назад
how can we use express js in next js project??
@DaveGrayTeachesCode
@DaveGrayTeachesCode Год назад
Express is a different framework. If using Express in the backend, I would keep it separate from the Next.js which would only be used in the frontend.
@aminbenz
@aminbenz Год назад
Hey Dave, Any way to catch API route errors globally in Nextjs13? and thnx
@DaveGrayTeachesCode
@DaveGrayTeachesCode Год назад
That would be nice - like we do in Node.js - but I am not currently aware of it.
@Trinita1970
@Trinita1970 Год назад
glorious
@abdulrahmanagboolaosho3582
@abdulrahmanagboolaosho3582 Год назад
Is this the end of the course
@DaveGrayTeachesCode
@DaveGrayTeachesCode Год назад
Not yet.
@Drewmssu
@Drewmssu Год назад
crolo
@IamAgrocerybag
@IamAgrocerybag 7 месяцев назад
Its torture that Next.js added all of this abstraction for getting object data out of a freaking fetch. Furthermore Next docs are unacceptable. Working with Next has been a big L.
@alsherifkhalaf7385
@alsherifkhalaf7385 Год назад
I tried to upload file , i thought it its standard web api to use formData , but i think the api route handlers parse data or change it : import { Directus } from '@directus/sdk'; import { NextResponse } from 'next/server'; export async function POST(request: Request) { const formData = await request.formData(); const file = formData.get('file'); formData.append('folder', '887b5198-6b28-4289-8117-87deb4df5e71'); formData.append('file', file as File); console.log("form data", formData); const token: string = process.env.DIRECTUS_JOB_TOKEN!; const url: string = process.env.DIRECTUS_URL!; const directus = new Directus(url); await directus.auth.static(token); const fileResponse = await directus.files.createOne(formData); return NextResponse.json({ "message": "File Uploaded" }); } the Axios error : [AxiosError: Data after transformation must be a string, an ArrayBuffer, a Buffer, or a Stream] even if i tried this on client side it works fine : const handleSubmit = async (event: React.FormEvent) => { event.preventDefault(); const form = new FormData(event.currentTarget); console.log(form) // this using api route handler // const response = await fetch('/api/job', { // method: 'POST', // body: form, // }) // console.log(response) const directus = new Directus('example.com/'); await directus.auth.static('secretkeys'); form.append('folder', '887b5198-6b28-4289-8117-87deb4df5e71'); const file = form.get('file'); if (file instanceof Blob) { form.append('file', file); } else { throw new Error('Invalid file data'); } const fileRes = directus.files.createOne(form) .then(async (Response) => { return await Response?.data.id; }) .catch(error => { console.error(error); }); console.log(fileRes) }; why is that ? is api route handlers parsing or changing the formData ?
@kiyama24
@kiyama24 Год назад
Discord id please...
@DaveGrayTeachesCode
@DaveGrayTeachesCode Год назад
Link to my Discord server in the description.
Далее
How to Build a REST API with Next.js 13
31:17
Просмотров 99 тыс.
Каха и жена (недопонимание)
00:37
9월 15일 💙
1:23:23
Просмотров 1,1 млн
The Story of Next.js
12:13
Просмотров 576 тыс.
Next.js App Router: Routing, Data Fetching, Caching
14:32
The Ultimate Guide To Next.js Route Handlers - CRUD
1:14:53
NextJS Parallel Routes Explained with a Simple Example
14:04
Каха и жена (недопонимание)
00:37