elysiajs / elysia

Ergonomic Framework for Humans
https://elysiajs.com
MIT License
9.23k stars 198 forks source link

Set Content-Type of request body #634

Open tialki opened 2 months ago

tialki commented 2 months ago

What is the problem this feature would solve?

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

new Elysia()
  .parser('application/json-patch+json', ({ request }) => request.json())
  .patch('/movies', () => {}, {
    body: t.Array(
      t.Union([
        t.Object({
          op: t.Union([t.Literal('test'), t.Literal('replace'), t.Literal('add')], {
            description: 'test | replace',
          }),
          path: t.String(),
          value: t.Any(),
        }),
        t.Object({
          op: t.Literal('remove', {
            description: 'remove',
          }),
          path: t.String(),
        }),
        t.Object({
          op: t.Union([t.Literal('move'), t.Literal('copy')], {
            description: 'move | copy',
          }),
          from: t.String(),
          path: t.String(),
        }),
      ])
    ),
    requestBodyType: 'application/json-patch+json'
  })

What alternatives have you considered?

No response