Next.js Discord

Discord Forum

Call Route (POST) from component in Next.JS 13?

Unanswered
Sloth bear posted this in #help-forum
Open in Discord
Sloth bearOP
I have a route: src/app/api/register/route.js with a POST() method
Trying to call this from: src/components/subpages/register-form.js

Currently I have below:
      // TODO: Handle this better?
      const res = await fetch('http://localhost:3000/api/register', {
        method: 'POST',
        headers: {
          'Content-Type': 'application/json'
        },
        body: JSON.stringify(form)
      })
`
How do I do call it in Next.js 13?

0 Replies