TopGit theo dõi koajs/koa-body trên GitHub, đã đạt 954 sao. koa body parser middleware
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
A full-featured koa body parser middleware. Supports multipart, urlencoded, and json request bodies. Provides the same functionality as Express's bodyParser - multer.
Install
Install with npm
npm install koa-body
Features
can handle requests such as:
multipart/form-data
application/x-www-form-urlencoded
application/json
application/json-patch+json
application/vnd.api+json
application/csp-report
application/reports+json
text/xml
configurable content-type matchers per body kind (jsonTypes, urlencodedTypes, textTypes, multipartTypes) for vendor or custom mime types
HTTP/1.1 200 OK
Content-Type: text/plain; charset=utf-8
Content-Length: 29
Date: Wed, 03 May 2017 02:09:44 GMT
Connection: keep-alive
Request Body: {"name":"test"}%
For a more comprehensive example, seeexamples/multipart.js
Usage with @koa/router
It's generally better to only parse the body as needed, if using a router that supports middleware composition, we can inject it only for certain routes.
For unsupported text body type, for example, text/xml, you can use the unparsed request body at ctx.request.body. For the text content type, the includeUnparsed setting is not required.
text{Boolean} Parse text bodies, such as XML, default true
json{Boolean} Parse JSON bodies, default true
jsonStrict{Boolean} Toggles co-body strict mode; if set to true - only parses arrays or objects, default true
jsonTypes{String[]} Content-types matched as JSON bodies (passed to ctx.is(...)), default ['application/json', 'application/json-patch+json', 'application/vnd.api+json', 'application/csp-report', 'application/reports+json']
urlencodedTypes{String[]} Content-types matched as urlencoded bodies (passed to ctx.is(...)), default ['urlencoded']
textTypes{String[]} Content-types matched as text bodies (passed to ctx.is(...)), default ['text/*']
multipartTypes{String[]} Content-types matched as multipart bodies (passed to ctx.is(...)), default ['multipart']
includeUnparsed{Boolean} Toggles co-body returnRawBody option; if set to true, for form encoded and JSON requests the raw, unparsed request body will be attached to ctx.request.rawBody, default false
formidable{Object} Options to pass to the formidable multipart parser
onError{Function} Custom error handle, if throw an error, you can customize the response - onError(error, context), default will throw
parsedMethods{String[]} Declares the HTTP methods where bodies will be parsed, default ['POST', 'PUT', 'PATCH']. Replaces strict option.
A note about parsedMethods
see http://tools.ietf.org/html/draft-ietf-httpbis-p2-semantics-19#section-6.3
GET, HEAD, and DELETE requests have no defined semantics for the request body, but this doesn't mean they may not be valid in certain use cases.
koa-body is strict by default, parsing only POST, PUT, and PATCH requests
you may use either the enumeration or strings to chose which methods to parse: For example, HttpMethodEnum.PATCH
File Support
Uploaded files are accessible via ctx.request.files.
A note about unparsed request bodies
Some applications require cryptographic verification of request bodies, for example webhooks from slack or stripe. The unparsed body can be accessed if includeUnparsed is true in koa-body's options. Then the unparsed body is available at ctx.request.rawBody. This only works for non multipart bodies.
Some options for formidable
See node-formidable for a full list of options
maxFields{Integer} Limits the number of fields that the querystring parser will decode, default 1000
maxFieldsSize{Integer} Limits the amount of memory all fields together (except files) can allocate in bytes. If this value is exceeded, an 'error' event is emitted, default 2mb (2 * 1024 * 1024)
uploadDir{String} Sets the directory for placing file uploads in, default os.tmpDir()
keepExtensions{Boolean} Files written to uploadDir will include the extensions of the original files, default false
hashAlgorithm{String} If you want checksums calculated for incoming files, set this to either 'sha1' or 'md5', default false
multiples{Boolean} Multiple file uploads or no, default true
onFileBegin{Function} Special callback on file begin. The function is executed directly by formidable. It can be used to rename files before saving them to disk. See the docs
onPart{Function} Overrides the default onPart of formidable. The function can be used to filter out parts based on their mimetype. For more use cases. See the docs
Changelog
Please see the Changelog for a summary of changes.
Tests
$ npm test
License
The MIT License, 2014 Charlike Mike Reagent (@tunnckoCore) and Daryl Lau (@daryllau)
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/koajs/koa-body là nguồn chính thức.
koajs/koa-body có bao nhiêu sao?
koajs/koa-body có 954 sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/koajs/koa-body. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
koajs/koa-body có phải mã nguồn mở không?
Có — koajs/koa-body phát hành theo license MIT, nghĩa là mã nguồn mở để đọc, fork và (tùy license) tái sử dụng. Mã: github.com/koajs/koa-body.
koajs/koa-body có tag gì không?
Bản đồng bộ chưa ghi nhận topic GitHub nào cho koajs/koa-body. GitHub topics hiển thị ở thanh bên phải trang repo — đó là nơi đáng kiểm tra nhất.
koajs/koa-body có website riêng không?
TopGit chưa ghi nhận URL trang chủ cho koajs/koa-body. Phần README ở tab phía trên thường có link demo, hoặc xem mô tả GitHub của repo.
koajs/koa-body còn đang phát triển không?
Commit gần nhất trên koajs/koa-body là 21 ngày trước (theo timestamp GitHub). Repo có 130 fork — một chỉ báo về mức độ quan tâm của cộng đồng.
Đọc đầy đủ README ở tab phía trên.
Vẫn đang phân vân về koa-body?
Một cú bấm sẽ gửi câu hỏi kèm trang này cho AI — xem AI nói gì về koa-body.