So i am building backend of a blog application and almost every other route is working just fine but for some reason route blogRouter.get(‘/:id’) is not
(This route is suppose to return blog whose id is being send in the get req).
I am building this backend using prisma ,avien(PostgresDB), couldflare workers and Hono
Here is the code i am working with 🙁https://i.sstatic.net/j7fajfFd.png)
I am having problem with this section of code :
`
blogRouter.get(‘/:id’,async (c) => {
const id = c.req.param('id')
const ID = Number(id)
const prisma = new PrismaClient({
datasourceUrl : c.env.DATABASE_URL,
}).$extends(withAccelerate())
console.log('Extracted id param:', id)
console.log('Parsed id:', ID)
if(isNaN(ID)){
return c.json({msg : "InValid id",Number : ID, parms:id})
}
`
And while sending the get request at postman i am getting this result :-
Get request : "http://localhost:8787/api/v1/blog/:2"
Response : { "msg": "InValid id", "Number": null, "parms": ":2" }
2
Answers
http://localhost:8787/api/v1/blog/:2
I think this url is wrong:2
After sending it you convert it withNumber(id)
, but:2
cannot be converted to numberhttp://localhost:8787/api/v1/blog/2
try it like this