elysia icon indicating copy to clipboard operation
elysia copied to clipboard

Option to skip parsing

Open bogeychan opened this issue 11 months ago • 3 comments

What is the problem this feature would solve?

Some routes, as mentioned in the documentation, don't require automatic body parsing at all and break if it occurs because the body is used due to side effects introduced by plugins (i.e. how elysia works)

What is the feature you are proposing to solve the problem?

Allow parse: false option in the route's configuration, or reconsider parsing for plugins that don't access the body but Context

app.post("/", betterAuthView, {
  parse: false,
});

Allowing something like this should also improve performance

What alternatives have you considered?

I tried this, but it is inconsistent with aot: false, in some cases and bad UX:

app.post("/", betterAuthView, {
  parse: () => 0,
});

bogeychan avatar Jan 10 '25 03:01 bogeychan

Also would appreciate this - we just ran into a case where we wanted to write a POST handler that doesn't have a body. We can't change the method for backwards compatibility reasons

sigmachirality avatar Feb 08 '25 03:02 sigmachirality

Also would like this. A third party package does a await req.body.text() which results in an "body already in use" if it was already parsed

dominictobias avatar Apr 20 '25 16:04 dominictobias

Never mind I see from the linked issue I can do:

body: t.String(),
parse: ctx => {
  const cloned = ctx.request.clone()
  return cloned.text()
}

dominictobias avatar Apr 20 '25 16:04 dominictobias

new Elysia().get(
    '/',
    ({ body }) => body ?? 'no body?',
    {
    	parse: 'none',
    }
)

SaltyAom avatar Aug 07 '25 16:08 SaltyAom

Image

bogeychan avatar Aug 07 '25 21:08 bogeychan