Skip to content

Commit 60e6969

Browse files
committed
Add usage example for parse function.
1 parent 8cbbf13 commit 60e6969

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

lib/parse.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,38 @@ const defaults: ParseOptions = {
3535
castTypes: true
3636
}
3737

38+
/**
39+
* Parses `multipart/form-data` body and returns an object with the data of that body
40+
*
41+
* @param request HTTP IncomingMessage object
42+
* @param options Parser options
43+
*
44+
* Simplest usage example:
45+
*
46+
* ```js
47+
* import {createServer} from "http"
48+
* import {parse} from "then-busboy"
49+
*
50+
* const handler = (req, res) => parse(req)
51+
* .then(async body => {
52+
* const result = []
53+
*
54+
* for (const [path, value] of body) {
55+
* result.push([path, isFile(value) ? await value.text() : value])
56+
* }
57+
*
58+
* res.setHeader("Content-Type", "application/json")
59+
* res.end(JSON.stringify(Body.json(result)))
60+
* })
61+
* .catch(error => {
62+
* res.statusCode = error.status || 500
63+
* res.end(error.message)
64+
* })
65+
*
66+
* createServer(handler)
67+
* .listen(2319, () => console.log("Server started on http://localhost:2319"))
68+
* ```
69+
*/
3870
export const parse = (
3971
request: IncomingMessage,
4072
options: ParseOptions = {}

0 commit comments

Comments
 (0)