Next.js Discord

Discord Forum

API Route Help - Transitioning from Pages to App Directory.

Answered
Smultar.json posted this in #help-forum
Open in Discord
I'm trying to create a basic get api router under /api/tasks. When visiting the page or trying to do anything with this route. I'm getting something as an error about create context?

I know the difference between client and server, however does this apply for api routes?

export default function handler(request: NextApiRequest, response: NextApiResponse<ResponseData>) {
    return response.status(200).json({ message: 'Hello' });
}
Answered by Smultar.json
Also my problem was, I was exporting as default, when it should have been export async GET
View full answer

5 Replies

It appears I have confused documentation
For anyone trying to make routers for the APP directory format, dont forget to hit this lil guy in the top right corner.
Also my problem was, I was exporting as default, when it should have been export async GET
Answer