subtext
Installation:

npm: npm install @hapi/subtext

yarn: yarn add @hapi/subtext

Introduction

subtext parses the request body and returns it in a promise.

Example

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/');

Methods

Subtext.parse(request, tap, options)

Parses the request body and returns it in a promise.

options are the following:

  • parse: (required) boolean
  • output: (required) 'data', 'stream', 'file'
  • maxBytes: int
  • override: string
  • defaultContentType: string
  • allow: string, only allow a certain media type
  • timeout: integer, limit time spent buffering request
  • qs: object, to pass into the qs module
  • uploads: string, directory for file uploads
  • decoders: an object mapping content-encoding names to their corresponding decoder functions
  • compression: an object mapping content-encoding names to their corresponding options passed to the decoders functions

returns the following:

  • payload: the parsed payload, or null if no payload
  • mime: the content type of the request

Changelog

#72
Fix maxBytes in file output
#70
Update deps
#69
Change module namespace
#66
Protect against JSON.parse() prototype poisoning
#63
Remove engines
#62
Only include file headers on multipart
#61
Update hoek v6
#60
Handle PromiseRejectionHandledWarning
#58
Cleanup
#56
Cleaner throw
#55
Update deps
#54
Update wreck
#53
Update pez dependency
#52
Update deps
#51
Update content
6.0.0
breaking changes
#50
Async interface
#49
Migrate to async interface
#73
maxBytes file output
#68
Commercial version of v5 branch
#67
Protect against JSON.parse() prototype poisoning
5.0.0
breaking changes
#48
Return 413 when payload too large.
#47
Update deps.
#45
Allow specifying custom query string parser
#44
Retain raw payload when parsing fails
#41
Support multipart override
#40
Support multipart override output
#37
Update dependencies
#36
Pass options to built-in compressions
#35
Support compression options
#34
Support external decoders
#33
Update deps
#29
update to code v3
#28
update form-data dependency to 0.2.x
#27
testing-node-6
#26
Return error for multipart file exceeding maxBytes
4.0.0
breaking changes
#25
Remove qs support. Closes #24
#24
Remove qs dependency
#23
Fix timeouts for multipart payloads
#19
timeout for payload not working.
3.0.0
breaking changes
#22
ES6 style changes and node v4
#21
Missing dependency qs@4.x.x?
#20
2.0.2 tag
#18
upgrade to lab 6 and cleanup
#17
testing different file sizes to get full code coverage
#16
Test coverage timing issue
#15
Move API docs to its own page
#14
Move API docs to their own page
#13
Update README with example and docs
2.0.0
breaking changes
#12
Default mime type option
#11
Change empty representations
#10
Change default mime type to application/octet-stream
#5
Error for payloads with content-encoding that fail maxBytes test
#9
Don't catch synchronous handler errors
#7
adding the ability to pass qs options like arrayLimit
#1
Files left behind when request aborts
clipboard