Next 13 api route endpoint returning 404 Not Found
Unanswered
Azro0891 posted this in #help-forum
Azro0891OP
Hi guys, i am creating a portfolio website with Next 13 using the new app directory and i am trying to introduce a database and authentication into my project by first testing my api endpoints using postman however all i seem to be getting back is a Not Found 404 page
I have followed the docs precisely making sure i create my folder structure correctly using a route.js file:
app/api/projects/route.js
I created another folder called projects inside of the api folder just to separate my resource endpoints. Inside of route.js i declared a route handler for a GET request which makes a fetch to the endpoint (http://localhost:8080/projects) created by json-server package (a local json file containing some of my projects) and inside the handler i return the data by using the json method on the NextResponse object:
In postman i make a request to the api endpoint provided by my local dev server (http://localhost:3000/api/projects) which should return my projects data
I have been over and over reading docs and i have checked and double checked for any typo's and everything seems to be done correctly and this is really basic stuff
What I've tried so far..
I've tried removing the /projects folder and just having the route path (http://localhost:3000/api)
I've tried Next 12 way of doing it using the pages folder in the root dir
pages/api/index.js
and in index using a default export:
I still get Not Found 404
I am half way through my website and i am now considering to abandon this approach and maybe use Firebase or another service instead to handle the back end
Any kind of help would be greatly appreciated
I have followed the docs precisely making sure i create my folder structure correctly using a route.js file:
app/api/projects/route.js
I created another folder called projects inside of the api folder just to separate my resource endpoints. Inside of route.js i declared a route handler for a GET request which makes a fetch to the endpoint (http://localhost:8080/projects) created by json-server package (a local json file containing some of my projects) and inside the handler i return the data by using the json method on the NextResponse object:
import { NextResponse } from "next/server"
export async function GET() {
const res = await fetch('http://localhost:8080/projects')
const projects = await res.json()
return NextResponse.json(projects, {
status: 200
})
}In postman i make a request to the api endpoint provided by my local dev server (http://localhost:3000/api/projects) which should return my projects data
I have been over and over reading docs and i have checked and double checked for any typo's and everything seems to be done correctly and this is really basic stuff
What I've tried so far..
I've tried removing the /projects folder and just having the route path (http://localhost:3000/api)
I've tried Next 12 way of doing it using the pages folder in the root dir
pages/api/index.js
and in index using a default export:
export default function handler(req, res) {
res.status(200).json({ message: 'Hello from Next.js!' })
}I still get Not Found 404
I am half way through my website and i am now considering to abandon this approach and maybe use Firebase or another service instead to handle the back end
Any kind of help would be greatly appreciated