raynos / body Goto Github PK
View Code? Open in Web Editor NEWBody parsing
License: MIT License
Body parsing
License: MIT License
If body
were to contain a weakmap cache of HttpRequest
=> raw body
it means you would be able to use body(req, res, cb)
anywhere irregardless of whether it has already been parsed.
This would be useful in an application where you don't want to do req.body = body
or context.body = body
but still want to read the body.
Is this a good idea?
cc @jonathanong
So anyBody
only really accepts json or form encoded bodies, which makes the name of the function a bit confusing.
I would expect it to fall back to the default textBody
implementation, especially for content types of text/*
@Raynos currently body
is using "error": "~2.0.4",
which has now 7.x package, will be good to update the dependency.
was thinking about this during dinner. would be nice if we refactored this so it could be more of a body parsing utility vs "middleware". then connect could depend on this. also, i don't like how koa-body-parser
modifies the context, so making this a yieldable would eliminate the need for koa-body-parser
some thoughts:
body(req, options, callback)
, body.json(req, options, callback)
, and body.urlencoded(req, options, callback)
signatures. not sure what options to pass other than those to raw-body.body = require('body')(options)
var obj = yield body(this.req, options)
in koa, but could be used in any generator-based control flow.http.ServerResponse
instance so we don't have to do something like app.use(body.json.middleware(options))
though I'm not sure how to set options.some other things required for connect backwards compatibility:
qs
as the url encoded parserneeded for connect backwards compatibility.
@jonathanong authored raw-body which has very similar concerns
Either I should depend on it or maybe this module should just be merged with it.
strict means only allowing objects and arrays as bodies and should be true
by default. needed for connect backwards compatibility.
any chance of supporting .req
or maybe we could formalize something akin to .toJSON() for libs that encapsulate node's objects
var body = yield jsonBody(req, res)
var body = yield jsonBody(this)
api-wise maybe instead of "reaching" into module:
var parse = require('body');
var body = yield parse.json(this);
and for any just:
var parse = require('body');
var body = yield parse(this);
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.