How to get data from app/api routes in next js on page?
Unanswered
Iridescent shark posted this in #help-forum
Iridescent sharkOP
I want to have api route app/api/folder/slug and page /folder/slug, and I want to fetch data from next js api to show it on page. How can I do it? I don't want to get data directly from database or use server action, I need receive data from next js api, because I want to reuse api routes in other apps. Can I use fetch or axios and have my component server side rendered? What is your suggestion to do it?
1 Reply
I would create a reusable function which can run on the page and the api route instead of fetching own api in page component which is not a good way to do
https://nextjs-faq.com/fetch-api-in-rsc
https://nextjs-faq.com/fetch-api-in-rsc