honojs / hono

Web framework built on Web Standards
https://hono.dev
MIT License
18.78k stars 534 forks source link

[PATCH] Path not retrieving Body #3410

Closed gzigurella closed 1 week ago

gzigurella commented 1 week ago

What version of Hono are you using?

4.6.1

What runtime/platform is your app running on?

Bun

What steps can reproduce the bug?

const app = new Hono();
const collaboratorsPath = app.basePath("/collaborators");

collaboratorsPath.patch('/collaborator/:id', async (c) => {
  const {id} = c.req.param();
  const {body} = await c.req.text();
  console.log(body);
}

What is the expected behavior?

Should get at least the text/plain body.

What do you see instead?

undefined

Additional information

I'm using the route to update an entity by Id, the request body always ends up undefined, even while checking from raw. Tried multiple HTTP client before opening the request (Postman, Insomnia, cURL, wget) to check if it was a problem on the client side.

The problem was found with text and json bodies on Patch requests.

An example of body passed

{
    "Email": "testPatch@development.it",
    "FirstName": "patchname",
    "LastName": "TestUserPatched",
    "password": "test",
    "passwordIsEncrypted": false
}

For further explanation I'm needing the text/plain and not a JSON due to further checks through Zod transformation.

gzigurella commented 1 week ago

I'm so fucking stupid and too tired. I fucking left brackets in the variable name. These shifts are killing my sanity. Sorry for the issue.