adonisjs / http-server

AdonisJS HTTP Server along with its Router
https://docs.adonisjs.com/guides/http
MIT License
112 stars 28 forks source link

Add 'requestBody' to RequestContract interface ('@ioc:Adonis/Core/Request' typings) #43

Closed pavel-voronin closed 3 years ago

pavel-voronin commented 3 years ago

Why this feature is required (specific use-cases will be appreciated)?

It's very convenient to use ES6's Object Destructuring in controllers:

...
  public async register({
    request: {
      requestBody: { username, password },
    },
    response,
  }: HttpContextContract) {
    await UserService.create({ username, password })

    response.status(204)
  }
...

Have you tried any other work arounds?

typings/Request.d.ts:

declare module '@ioc:Adonis/Core/Request' {
  export interface RequestContract {
    requestBody: Record<string, any>
  }
}

Are you willing to work on it with little guidance?

No

thetutlage commented 3 years ago

Not something I would like to add to the core. However, you can add it using getters and macros. https://docs.adonisjs.com/guides/request#extending-request-class