Тёмный

Build a REST API in Next.js 13 app directory! Master RESTful techniques and paging w/ Prisma & Auth! 

Build SaaS with Ethan
Подписаться 7 тыс.
Просмотров 9 тыс.
50% 1

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

 

14 окт 2024

Поделиться:

Ссылка:

Скачать:

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

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 70   
@georgenabraham
@georgenabraham Год назад
Thank you for this awesome video, it is really a lot of effort for 6k views. I hope your channel gets bigger soon.
@ethan_mick
@ethan_mick Год назад
Thanks, this video has been consistently helpful for people. That's all I can ask for!
@anuj7286
@anuj7286 Год назад
Thankyou for providing such a great content. Love from India.
@ethan_mick
@ethan_mick Год назад
Thank you for watching and supporting me!
@ethan_mick
@ethan_mick Год назад
@private-comment I'll start tracking some productivity hacks and can put together a video that.
@muhamadbadriyusuf5686
@muhamadbadriyusuf5686 Год назад
Amazing..underrated video of new things i learnt that cant get even in 10 hours video tutorial...thank you...
@ethan_mick
@ethan_mick Год назад
Glad you liked it!
@mironmahmud9790
@mironmahmud9790 6 месяцев назад
I am reallay greatful to your valuable content. Thank you so much from Bangladesh
@nasarissa749
@nasarissa749 11 месяцев назад
Nice work. Hypothetically, how would you calculate the most popular dish at a restaurant?
@KelberStuchi
@KelberStuchi Год назад
Thank you for authorization explain and other important items like pagination. I appreciate that.
@ethan_mick
@ethan_mick Год назад
Thank you! I think these are important concepts to cover :)
@MasterWolFxMotionDesigner
@MasterWolFxMotionDesigner Год назад
Hello, very good guide! However i have a question, lets say that there is a page to view the resturant menu and the client does the required requests to the api to render data... lets also suppose that there is a dashboard for the owner of the resturant in which he can view, add and edit more sensitive data like suppliers for a certain product. I would like that that kind of data is visible only if the GET request is made from the owner of the resturant (logged in obviously). Is it a good idea to check for auth inside a GET request and eventually add more sensitive data? There is a better way to do this?
@ethan_mick
@ethan_mick Год назад
Adding the Authentication to each route works, but if you ever forget to add that auth check you could potentially leak information. If you need to progressively enhance responses then you could always return the "basic" information and then if they have permission, augment the response with more data that is sensitive. If the admin needs different routes to CRUD all those resources, consider using Middleware and put the role check there. Then you can check all the requests in the same place and have some logic that says "If admin, you can see/edit these resources, otherwise you can only read them". Having all that logic in the same place will be make it easier to understand what's happening and to update it later.
@Nahary
@Nahary Год назад
Could you make a video on how to implement pagination in frontend? I love your content ❤.
@ethan_mick
@ethan_mick Год назад
I've added it to the list, thanks!
@WaltonTheCat
@WaltonTheCat Год назад
You are awesome man. Thank you!
@ethan_mick
@ethan_mick Год назад
Thank YOU! Enjoy!
@notelab-l3j
@notelab-l3j Год назад
Well explained
@ethan_mick
@ethan_mick Год назад
Thanks ❤️
@spencerbigum1309
@spencerbigum1309 Год назад
Is the app dir ready for production at all yet? Really informative video - I want to get setup using supabase + prisma + next for my next project so I'll def be watching some more of your videos! Great job!
@ethan_mick
@ethan_mick Год назад
The Next.js team says it's still in Beta -- and it is. But it's gotten a lot more stable in 13.3. I think for any small app, it's basically ready to go. If you were building an enterprise app that needs stability, I'd hold for for a little longer. I think it'll come out of beta in the next couple of months.
@spencerbigum1309
@spencerbigum1309 Год назад
@@ethan_mick Ah thats awesome and bad at the same time. I'm in the middle of building a large headless blog to replace my main website. Should I be building in tandom lol. I don't think I can have the app dir enabled and still use pages as I migrate over slowly...
@ethan_mick
@ethan_mick Год назад
@@spencerbigum1309 First, don't panic! The most important thing is building something, and I highly recommend you keep on your path and get your blog done. Once you've gotten your new version out, you can start migrating to the App Dir. There's no rush to do so, the `pages` directory isn't going anywhere. You can slowly migrate (page by page) in the future, so you can wrap your head around the new structure. And hopefully my videos will help! Keep it up :)
@spencerbigum1309
@spencerbigum1309 Год назад
@@ethan_mick You make a really good point. Shipped is better than perfect, in this case, better than the latest update. Thanks a ton - will def be watching more and pobly more questions lol.
@francais-salvador
@francais-salvador Год назад
Hello Ethan, just to let to know that the links in your newsletter does not work. Ghost has some issues at this time. cheers.
@ethan_mick
@ethan_mick Год назад
Thanks for letting me know! I saw that my site was having some issues (status.ghost.org/)... hoping it gets cleared up soon...
@abderrahmaniidrissihamza1821
please Ethan what is the difference between working with api in the frontend and working directly with db with prisma? to be more clear what difference between data=await fetch('/api/restaurants) vs data=await prisma.restaurants.findMany() based on what we go for one or another?
@ethan_mick
@ethan_mick Год назад
In the first example you are making an HTTP request from the client to a server, which then (most likely) needs to query the database for the data. client -> server -> database In the second example, using Prisma, you are querying the database directly. client -> database. Fewer hops are better. When you can do the latter, you should. However this depends on *what* the client is and where it's located. If the client is a mobile app or a client side web app, it has NO access to the database. Therefore, it needs to go through the API server, and that usually happens with the fetch request. If the client is server side, then it can query the database directly and return the results (hydrating a page normally).
@abderrahmaniidrissihamza1821
@@ethan_mick Thanks Ethan I've been searching for an answer for a while even chatgpt didn't manage to give a clear answer as yours. you are the best .
@speedster784
@speedster784 Год назад
would it be possible for you to do a video about authentication where you implement verification by email using next auth credential not the magic link and go into details about different forms of authentication in next js
@ethan_mick
@ethan_mick Год назад
Interesting -- so you'd like to see Email + Password, but they need to verify the email after registering? Is that correct?
@speedster784
@speedster784 Год назад
@@ethan_mick yes that's correct.. but not with magic link but rather with credential providers with next auth
@abdurahmansheikh-omar4597
@abdurahmansheikh-omar4597 Год назад
fam you are theeeeeeeeeeee best 🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥
@ethan_mick
@ethan_mick Год назад
🔥🔥🔥
@shawn-skull
@shawn-skull Год назад
Whats the difference between "return NextResponse(...)" and "return new NextResponse(...)"
@ethan_mick
@ethan_mick Год назад
NextResponse extends the Response class (developer.mozilla.org/en-US/docs/Web/API/Response). It's an actual class, not a function, so you need to instantiate it when you use it. That's what the keyword `new` does here.
@Mr.MaxaaCusub
@Mr.MaxaaCusub Год назад
thank you for the explanation like pagination and others. How to get file in request body in nextjs 13.2 api route
@ethan_mick
@ethan_mick Год назад
Thanks for the kind works! Take a look at this: ethanmick.com/how-to-upload-a-file-in-next-js-13-app-directory/
@cb73
@cb73 Год назад
Nice work… a small detail but I would have made menu items a many-to-many relationship to menu since menu items might be able to exist in multiple menus. To get around the floating point issue for price, I always store prices in cents therefore as an integer. E.g. $20.99 is stored as 2099
@ethan_mick
@ethan_mick Год назад
You know... yeah, MenuItems being many-to-many is a great idea. I was thinking too much about the API structure when I put this together but if you were to build it, you would definitely want that. Mind if I put that into the write up? For money, that's definitely a viable strategy. I'd also take a look at things like www.postgresql.org/docs/15/datatype-money.html for whatever database you're using.
@patrickudeh5869
@patrickudeh5869 Год назад
Great job 👍... Will like to see the codes in JavaScript not typescript...
@hironakae
@hironakae Год назад
Hi, could you share with us what you are using at 6:35 to view the database? your videos are awesome btw 🎉
@ethan_mick
@ethan_mick Год назад
Yep, it's eggerapps.at/postico2/ ! It costs ~$60, so not cheap, but it's so helpful when working with Postgres.
@faizanahmed9304
@faizanahmed9304 Год назад
Amazing video!
@ethan_mick
@ethan_mick Год назад
Thanks!
@eliuddyn
@eliuddyn Год назад
Amazing content 🔥🔥
@ethan_mick
@ethan_mick Год назад
Thanks! 🔥
@ronaldpaek
@ronaldpaek Год назад
If I use server components how can I wrap my application with a client side state management like RTK or react context and still have my app take advantage of server componts, I'm not good at this new mental model, was wondering for things like state for things like dark mode toggling for tailwind
@ethan_mick
@ethan_mick Год назад
This won't work the way you want it to. The server components run on the server and won't share the client state. You can lookup information about the request (like cookies/headers) and use that to know some details about the request.
@amariliodeoliveira
@amariliodeoliveira Год назад
I appreciate it if you could show me your package.json to see which dependencies you have installed.
@ethan_mick
@ethan_mick Год назад
Here ya go! github.com/ethanmick/nextjs-rest-api/blob/main/package.json Honestly nothing too exciting in there.
@ronaldpaek
@ronaldpaek Год назад
I am very new to backend stuff, if I end up using supabase with prisma as the ORM will the steps you provided on your videos work? I was working with others and they were having a lot of trouble with authentication, since they were not able to figure it out I am trying to connect the dots, or find resources that might be able to help me finish my app. Thank you for your videos they are amazing
@ethan_mick
@ethan_mick Год назад
Yes, Prisma will work great with Supabase. You can use the Supabase connection string you get in your `.env` file.
@Iamroot27
@Iamroot27 Год назад
Hi please I’m having issues working with login page , can you make a video which has login page different from register page ..
@ethan_mick
@ethan_mick Год назад
Surprised the algorithm didn't help you out friend: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-cm-7RmD8yKQ.html
@martinntalika2712
@martinntalika2712 Год назад
you the 🐐🔥
@ethan_mick
@ethan_mick Год назад
Thank you! 🔥🔥
@kevinfarley7359
@kevinfarley7359 Год назад
how can we check if user supplied an "apikey", and let the apikey be set in url
@ethan_mick
@ethan_mick Год назад
I suggest passing an API Key in the header, like: Authorization: Bearer api_key_here Or a custom header X-API-KEY: api_key_herer And then read it from the headers. Or, if you pass it in the URL, use a query parameter and read it out that way.
@pbdivyesh
@pbdivyesh Год назад
Can you please also make a video where how we can seprate the business logic from the routes, so that like creating a service folder that serves the logic. This can create the functions in route.ts files like only barely 2 lines. I have been rejected from a job just as I did not create a service abstraction.
@ethan_mick
@ethan_mick Год назад
Interesting -- I would only recommend doing that if you are using the logic in multiple places. Otherwise it's an unnecessary abstraction, which is worse than no abstraction. However, this is a common request when building an API with React Server Components, since both will want to fetch the same data. I could whip something together around that.
@pbdivyesh
@pbdivyesh Год назад
​@@ethan_mick Exactly! I tried to explain this in kind way. Anyways I'm upto the other interviews now. In terms, of next.js and server components a common fetcher does make sense though that only server frontend focused components and I'm sure can't be utilised on the API. Thank you for the response. Appreciate your videos and looking forward to learn more from you :)
@ethan_mick
@ethan_mick Год назад
@@pbdivyesh Good luck on your interviews!
@josepedrodeferreira2655
@josepedrodeferreira2655 Год назад
who would guess jim halpert would be teaching me how to code
@ethan_mick
@ethan_mick Год назад
You know, I've actually gotten that quite a lot, lol. And from a surprising places too.
@matusalem2961
@matusalem2961 5 месяцев назад
thanks brother, flamengo is the best team in the world! Palmeiras no have "Mundial de clubes" ai hate Vitinho
@ronaldpaek
@ronaldpaek Год назад
I was getting errors on the api calls not working for me but when I change the returns like this they work now, return new NextResponse(JSON.stringify(restaurant), { status: 200 })
@ethan_mick
@ethan_mick Год назад
Glad you got it working!
Далее
How to write a Solana program in Assembly
31:08
What Theo Won't Tell You About Next.js
8:37
Просмотров 93 тыс.
Set up Google OAuth with Next.js using Next-Auth!
21:00