fetch problem
Answered
Bull Arab posted this in #help-forum
Bull ArabOP
so i've been watching some youtube video about CRUD Operations in youtube, and i saw people just fetching the api by using
localhost:3000/<api-path>, is this the right way to do it? because when we host it to lets say vercel, will this work?Answered by James4u
if you want to refer videos, I recommend you to look for videos from lee robinson
36 Replies
@Bull Arab do you make that request from the client side?
Bull ArabOP
no
from server side
well, are you using app router?
Bull ArabOP
nextjs needs it?
doesn't it does by itself?
yeah, it's recommended by default
Bull ArabOP
im sorry if this sounds silly, im new to nextjs
when you bootstrap your project via create-next-app
Bull ArabOP
yeah!
see if you have
app directoryBull ArabOP
yeah i do.
i don't used pages
okay then you are using app router
Bull ArabOP
yes yes
in app router, you can use server actions for CRUD
Bull ArabOP
okay please answer this!
we shouldn't use localhost right
for fetching
no, y ou shouldn't
Bull ArabOP
what's the alternative way
yeah, you can do server side data fetching directly
in the server component you have access to the database
Bull ArabOP
like will dirs?
Bull ArabOP
like ../api/<routes> ?
nope, @Bull Arab you don't neeed api routes
if you are new to next.js app router, please take a look at documents I shared
Bull ArabOP
ok im confused, i'll check your links
yeah thank you sorry for being annoying
can you suggest some videos tho?
not sure why they prefer videos over the documents, hmm
Bull ArabOP
more clarification 😭
okay nvm thanks
if you want to refer videos, I recommend you to look for videos from lee robinson
Answer