Skip to content

Commit 849361f

Browse files
committed
updated docs
1 parent a77a104 commit 849361f

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

docs/docs/modules/http.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,58 @@ middleware = {
114114
```
115115

116116
middleware precedence is top to bottom. this is why everything works in the third example. `hello` has a value of blank array.
117+
118+
## request parsers
119+
120+
### application/json
121+
122+
`req.body` is populated with the parsed version of the request.
123+
124+
```json
125+
{"name": "exa", "type": "framework"}
126+
```
127+
128+
is parsed into
129+
130+
```js
131+
{
132+
name: 'exa',
133+
type: 'framework'
134+
}
135+
```
136+
137+
### application/x-www-form-urlencoded
138+
139+
`req.body` is populated with an object of key/value pairs representing the request.
140+
141+
```
142+
?name=exa&type=framework
143+
```
144+
145+
is parsed into
146+
147+
```js
148+
{
149+
name: 'exa',
150+
type: 'framework'
151+
}
152+
```
153+
154+
### multipart/form-data
155+
156+
same as above, `req.body` is populated with an object of key/value pairs representing the request **for only non-files**. `exa.js` uses [multer](https://www.npmjs.com/package/multer) middleware for `multipart/form-data` requests. by default, the in memory temporary storage is used.
157+
158+
for `multipart/form-data` requests, `req.files` is populated with an array of objects each representing an uploaded file. for example, a file uploaded with the name `cat` would cause `req.files` to look like this:
159+
160+
```js
161+
[
162+
{
163+
fieldname: 'cat',
164+
originalname: 'cool_cat.jpg',
165+
encoding: '7bit',
166+
mimetype: 'image/jpeg',
167+
buffer: <Buffer ff d8 ff e1 7f ... 1024 more bytes>,
168+
size: 7972467
169+
}
170+
]
171+
```

0 commit comments

Comments
 (0)