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
Avatar
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' });
}
Image
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

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