minimaal()

minimaal()

Creates an Minimaal application. The minimaal() function is a top-level function exported by the minimaal module.

app.js
const minimaal = require("minimaal");
const app = minimaal();

Methods

minimaal.json([options])

This is a built-in middleware function in Minimaal. It parses incoming requests with JSON payloads and is based on body-parser.

Returns middleware that only parses JSON and only looks at requests where the Content-Type header matches the type option. This parser accepts any Unicode encoding of the body and supports automatic inflation of gzip and deflate encodings.

A new body object containing the parsed data is populated on the request object after the middleware (i.e. req.body), or an empty object () if there was no body to parse, the Content-Type was not matched, or an error occurred.

The following table describes the properties of the optional options object.

PropertyDescriptionTypeDefault
inflateEnables or disables handling deflated (compressed) bodies; when disabled, deflated bodies are rejected.Booleantrue
limitControls the maximum request body size. If this is a number, then the value specifies the number of bytes; if it is a string, the value is passed to the bytes library for parsing.Mixed"100kb"
reviverThe reviver option is passed directly to JSON.parse as the second argument. You can find more information on this argument in the MDN documentation about JSON.parse.Functionnull
strictEnables or disables only accepting arrays and objects; when disabled will accept anything JSON.parse accepts.Booleantrue
typeThis is used to determine what media type the middleware will parse. This option can be a string, array of strings, or a function. If not a function, type option is passed directly to the type-is library and this can be an extension name (like json), a mime type (like application/json), or a mime type with a wildcard (like / or */json). If a function, the type option is called as fn(req) and the request is parsed if it returns a truthy value.Mixed"application/json"
verifyThis option, if supplied, is called as verify(req, res, buf, encoding), where buf is a Buffer of the raw request body and encoding is the encoding of the request. The parsing can be aborted by throwing an error.Functionundefined

minimaal.urlencoded([options])

This is a built-in middleware function in Minimaal. It parses incoming requests with urlencoded payloads and is based on body-parser.

Returns middleware that only parses urlencoded bodies and only looks at requests where the Content-Type header matches the type option. This parser accepts only UTF-8 encoding of the body and supports automatic inflation of gzip and deflate encodings.

A new body object containing the parsed data is populated on the request object after the middleware (i.e. req.body), or an empty object () if there was no body to parse, the Content-Type was not matched, or an error occurred. This object will contain key-value pairs, where the value can be a string or array (when extended is false), or any type (when extended is true).

The following table describes the properties of the optional options object.

PropertyDescriptionTypeDefault
extendedThis option allows to choose between parsing the URL-encoded data with the querystring library (when false) or the qs library (when true). The “extended” syntax allows for rich objects and arrays to be encoded into the URL-encoded format, allowing for a JSON-like experience with URL-encoded. For more information, please see the qs library.Booleanfalse
inflateEnables or disables handling deflated (compressed) bodies; when disabled, deflated bodies are rejected.Booleantrue
limitControls the maximum request body size. If this is a number, then the value specifies the number of bytes; if it is a string, the value is passed to the bytes library for parsing.Mixed"100kb"
parameterLimitThis option controls the maximum number of parameters that are allowed in the URL-encoded data. If a request contains more parameters than this value, an error will be raised.Number1000
typeThis is used to determine what media type the middleware will parse. This option can be a string, array of strings, or a function. If not a function, type option is passed directly to the type-is library and this can be an extension name (like urlencoded), a mime type (like application/x-www-form-urlencoded), or a mime type with a wildcard (like */x-www-form-urlencoded). If a function, the type option is called as fn(req) and the request is parsed if it returns a truthy value.Mixed"application/x-www-form-urlencoded"
verifyThis option, if supplied, is called as verify(req, res, buf, encoding), where buf is a Buffer of the raw request body and encoding is the encoding of the request. The parsing can be aborted by throwing an error.Functionundefined