subtext parses the request body and returns it in a promise.
const Http = require('http');
const Subtext = require('@hapi/subtext');
Http.createServer(async (request, response) => {
const { payload, mime } = await Subtext.parse(request, null, { parse: true, output: 'data' });
response.writeHead(200, { 'Content-Type': 'text/plain' });
response.end(`Payload contains: ${JSON.stringify(payload)}`);
}).listen(1337, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1337/');Parses the request body and returns it in a promise.
options are the following:
parse: (required) booleanoutput: (required) 'data', 'stream', 'file'maxBytes: intmaxParts: intoverride: stringdefaultContentType: stringallow: string, only allow a certain media typetimeout: integer, limit time spent buffering requestqs: object, to pass into the qs moduleuploads: string, directory for file uploadsdecoders: an object mapping content-encoding names to their corresponding decoder functionscompression: an object mapping content-encoding names to their corresponding options passed to thedecodersfunctions
returns the following:
payload: the parsed payload, or null if no payloadmime: the content type of the request