Next.js Discord

Discord Forum

How can I implement backend correctly?

Unanswered
Николя posted this in #help-forum
Open in Discord
Hello everyone, I'm a beginner developer, I'm making a website for watching anime, I use API, the question is how can I correctly get data from the API?
For example, I have a page with series selection with this path
/choose/[seriaId]
How can I properly make an API from a database?

I understand that I can get all the series from there, and then return the one that will be equal to the current [seriaId], but I want to make it in this form as shown here, how do I need to implement the api for this?
async function fetchSeria(id)
{
  const res = await fetch('http://localhost:3000/api/choose' + id)
  const result = await res.json();
  return result
}

async function page({params}) {
const info = await fetchSeria(params.seriaId)
  return (
    <div>seriaNumber {info.ID}</div>
  )
}

export default page

0 Replies