You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add a parseBody(parser) utility that can negotiate the content type of the form submissions, and returns the parsed body
Supports:
application/json
application/text
application/x-www-form-urlencoded
multipart/form-data (not available in Bun natively)
Example:
// your parsed bodyconstbody=awaitparseBody(ctx.request!)
Currently, plan to support reading all the content at once and improve it in the future version of the middleware (or when Bun natively supports multipart/form-data
Middleware
As a companion utility, add a body-parser middleware, that attaches the parsed payload to context ctx.body using the above utility.
Supports:
The middleware should support the following multipart/form-data configurations (all optional)
extensions - supported file extensions (default: all the extensions)
maxFileSizeBytes - supported maximum payload size per file (default: no restrictions)
maxSizeBytes - supported maximum payload size for all the files (default: no restrictions)
Example(basic):
import{BunTea}from'bun-tea'import{bodyParser}from'bun-tea/dist/mw/body-parser'constapp=newBunTea()app.post("/users",[bodyParser()],(ctx)=>{// get your parsed body here...// console.log(ctx.body)returnctx.json({message: "users created",});})app.listen({port: 3000},(server)=>{console.log(`Server started on ${server.port}`)})
Example(with configuration):
import{BunTea}from'bun-tea'import{bodyParser}from'bun-tea/dist/mw/body-parser'constapp=newBunTea()app.post("/users",[bodyParser({extensions: ['jpg'],maxFileSizeBytes: 2_4000,maxSizeBytes: 2_6000})],(ctx)=>{// get your parsed body here...// console.log(ctx.body)returnctx.json({message: "users created",});})app.listen({port: 3000},(server)=>{console.log(`Server started on ${server.port}`)})
The text was updated successfully, but these errors were encountered:
parseBody (utility/parser)
Add a
parseBody
(parser) utility that can negotiate the content type of the form submissions, and returns the parsed bodySupports:
application/json
application/text
application/x-www-form-urlencoded
multipart/form-data
(not available in Bun natively)Example:
Currently, plan to support reading all the content at once and improve it in the future version of the middleware (or when Bun natively supports
multipart/form-data
Middleware
As a companion utility, add a
body-parser
middleware, that attaches the parsed payload to contextctx.body
using the above utility.Supports:
The middleware should support the following
multipart/form-data
configurations (all optional)extensions
- supported file extensions (default: all the extensions)maxFileSizeBytes
- supported maximum payload size per file (default: no restrictions)maxSizeBytes
- supported maximum payload size for all the files (default: no restrictions)Example(basic):
Example(with configuration):
The text was updated successfully, but these errors were encountered: