The new middleware.
import assert from 'assert'
import createServer, { IHttpRequest, IHttpResponse, yaml } from '@egomobile/http-server'
const app = createServer()
// custom error handler
async function handleLimitReached(request: IHttpRequest, response: IHttpResponse) {
request.writeHead(400)
request.write('Input is too big')
}
// maximum input size: 128 MB
app.post('/', yaml(), async (request: IHttpRequest, response: IHttpResponse) => {
assert.strictEqual(Array.isArray(request.body), true)
})
// maximum input size: 256 MB
app.put('/', yaml(256), async (request: IHttpRequest, response: IHttpResponse) => {
assert.strictEqual(Array.isArray(request.body), true)
})
// maximum input size: 384 MB
app.patch('/', yaml({ limit: 402653184 }), async (request: IHttpRequest, response: IHttpResponse) => {
assert.strictEqual(Array.isArray(request.body), true)
})
app.delete('/', yaml({ limit: 1048576, onLimitReached: handleLimitReached }), async (request: IHttpRequest, response: IHttpResponse) => {
// alternative:
// app.delete('/', yaml(1, handleLimitReached), async (request: IHttpRequest, response: IHttpResponse) => {
assert.strictEqual(Array.isArray(request.body), true)
})
Optional
onLimitReached: Nilable<HttpRequestHandler>Optional
onParsingFailed: Nilable<ParseErrorHandler>Generated using TypeDoc
Creates a middleware, that reads the whole input of the request stream, parses it as YAML UTF-8 string and writes the object to 'body' property of the request context.