• Version 8.1.9
  • Published
  • 79.3 kB
  • 8 dependencies
  • MIT license


npm i @adonisjs/bodyparser
yarn add @adonisjs/bodyparser
pnpm add @adonisjs/bodyparser


AdonisJs body parser to read and parse HTTP request bodies



class BodyParserProvider

class BodyParserProvider {}


    constructor(app: ApplicationContract);

      property app

      protected app: ApplicationContract;

        property needsApplication

        static needsApplication: boolean;

          method boot

          boot: () => void;
          • Adding the file macro to add support for reading request files.

          method register

          register: () => void;
          • Registers the bodyparser middleware namespace to the container.


          namespace @ioc:Adonis/Core/BodyParser

          module '@ioc:Adonis/Core/BodyParser' {}

            variable BodyParserMiddleware

            const BodyParserMiddleware: BodyParserMiddlewareContract;

              interface BodyParserMiddlewareContract

              interface BodyParserMiddlewareContract {}
              • Shape of the bodyparser middleware class constructor

              construct signature

              new (config: BodyParserConfig): {
              handle(ctx: HttpContextContract, next: () => void): any;

                interface MultipartContract

                interface MultipartContract {}
                • Multipart class contract, since it is exposed on the request object, we need the interface to extend typings.

                property state

                state: 'idle' | 'processing' | 'error' | 'success';

                  method abort

                  abort: (error: any) => void;

                    method onFile

                    onFile: (
                    name: string,
                    options: Partial<FileValidationOptions & { deferValidations: boolean }>,
                    callback: PartHandler
                    ) => this;

                      method process

                      process: (
                      config?: Partial<{ limit: string | number; maxFields: number }>
                      ) => Promise<void>;

                        interface MultipartFileContract

                        interface MultipartFileContract {}
                        • Multipart file interface

                        property allowedExtensions

                        allowedExtensions?: string[];

                          property clientName

                          clientName: string;

                            property errors

                            errors: FileUploadError[];

                              property extname

                              extname?: string;

                                property fieldName

                                fieldName: string;

                                  property fileName

                                  fileName?: string;

                                    property filePath

                                    filePath?: string;

                                      property hasErrors

                                      hasErrors: boolean;

                                        property headers

                                        headers: {
                                        [key: string]: string;

                                          property isMultipartFile

                                          isMultipartFile: true;

                                            property isValid

                                            isValid: boolean;

                                              property meta

                                              meta: any;

                                                property size

                                                size: number;

                                                  property sizeLimit

                                                  sizeLimit?: number | string;

                                                    property state

                                                    state: 'idle' | 'streaming' | 'consumed' | 'moved';

                                                      property subtype

                                                      subtype?: string;

                                                        property tmpPath

                                                        tmpPath?: string;

                                                          property type

                                                          type?: string;

                                                            property validated

                                                            validated: boolean;

                                                              method markAsMoved

                                                              markAsMoved: (fileName: string, filePath: string) => void;
                                                              • Mark file as moved

                                                              method move

                                                              move: (
                                                              location: string,
                                                              options?: { name?: string; overwrite?: boolean }
                                                              ) => Promise<void>;
                                                              • Move file from temporary path to a different location. Self consumed streams cannot be moved unless tmpPath is defined explicitly.

                                                              method moveToDisk

                                                              moveToDisk: (
                                                              location: string,
                                                              options?: WriteOptions & { name?: string },
                                                              diskName?: keyof DisksList
                                                              ) => Promise<void>;
                                                              • Move file to a pre-registered drive disk

                                                              method toJSON

                                                              toJSON: () => FileJSON;
                                                              • Get JSON representation of file

                                                              method validate

                                                              validate: () => void;
                                                              • Run validations on the file

                                                              type BodyParserConfig

                                                              type BodyParserConfig = {
                                                              whitelistedMethods: string[];
                                                              json: BodyParserJSONConfig;
                                                              form: BodyParserFormConfig;
                                                              raw: BodyParserRawConfig;
                                                              multipart: BodyParserMultipartConfig;
                                                              • Body parser config for all different types

                                                              type BodyParserFormConfig

                                                              type BodyParserFormConfig = BodyParserBaseConfig & {
                                                              queryString: QueryStringConfig;
                                                              convertEmptyStringsToNull: boolean;
                                                              • Parser config for parsing form data

                                                              type BodyParserJSONConfig

                                                              type BodyParserJSONConfig = BodyParserBaseConfig & {
                                                              strict: boolean;
                                                              • Body parser config for parsing JSON requests

                                                              type BodyParserMultipartConfig

                                                              type BodyParserMultipartConfig = BodyParserBaseConfig & {
                                                              autoProcess: boolean;
                                                              maxFields: number;
                                                              processManually: string[];
                                                              convertEmptyStringsToNull: boolean;
                                                              fieldsLimit?: number | string;
                                                              tmpFileName?(): string;
                                                              • Parser config for parsing multipart requests

                                                              type BodyParserRawConfig

                                                              type BodyParserRawConfig = BodyParserBaseConfig & {
                                                              queryString: QueryStringConfig;
                                                              • Parser config for parsing raw body (untouched)

                                                              type FileJSON

                                                              type FileJSON = {
                                                              fieldName: string;
                                                              clientName: string;
                                                              size: number;
                                                              filePath?: string;
                                                              fileName?: string;
                                                              type?: string;
                                                              extname?: string;
                                                              subtype?: string;
                                                              state: 'idle' | 'streaming' | 'consumed' | 'moved';
                                                              isValid: boolean;
                                                              validated: boolean;
                                                              errors: FileUploadError[];
                                                              meta: any;
                                                              • Shape of file.toJSON return value

                                                              type FileUploadError

                                                              type FileUploadError = {
                                                              fieldName: string;
                                                              clientName: string;
                                                              message: string;
                                                              type: 'size' | 'extname' | 'fatal';
                                                              • Error shape for file upload errors

                                                              type FileValidationOptions

                                                              type FileValidationOptions = {
                                                              size: string | number;
                                                              extnames: string[];
                                                              • The options that can be used to validate a given file

                                                              type MultipartStream

                                                              type MultipartStream = Readable & {
                                                              headers: {
                                                              [key: string]: string;
                                                              name: string;
                                                              filename: string;
                                                              bytes: number;
                                                              file: MultipartFileContract;
                                                              • Readable stream along with some extra data. This is what is passed to onFile handlers.

                                                              type PartHandler

                                                              type PartHandler = (
                                                              part: MultipartStream,
                                                              reportChunk: (chunk: Buffer) => void
                                                              ) => Promise<
                                                              | ({
                                                              filePath?: string;
                                                              tmpPath?: string;
                                                              } & {
                                                              [key: string]: any;
                                                              | void
                                                              • The callback handler for a given file part

                                                              namespace @ioc:Adonis/Core/Request

                                                              module '@ioc:Adonis/Core/Request' {}
                                                              • Extending the request interface on the core module

                                                              interface RequestContract

                                                              interface RequestContract {}

                                                                property multipart

                                                                multipart: MultipartContract;

                                                                  method allFiles

                                                                  allFiles: () => {
                                                                  [field: string]: MultipartFileContract | MultipartFileContract[];

                                                                    method file

                                                                    file: (
                                                                    key: string,
                                                                    options?: Partial<FileValidationOptions>
                                                                    ) => MultipartFileContract | null;

                                                                      method files

                                                                      files: (
                                                                      key: string,
                                                                      options?: Partial<FileValidationOptions>
                                                                      ) => MultipartFileContract[];

                                                                        Package Files (3)

                                                                        Dependencies (8)

                                                                        Dev Dependencies (33)

                                                                        Peer Dependencies (3)


                                                                        To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                                                                        You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@adonisjs/bodyparser.

                                                                        • Markdown
                                                                        • HTML
                                                                          <a href="https://www.jsdocs.io/package/@adonisjs/bodyparser"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>