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
Copy file name to clipboardExpand all lines: README.md
+17-16Lines changed: 17 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -22,14 +22,14 @@ This library adds an `xml` method to the `body-parser` object.
22
22
23
23
Initialise like so:
24
24
25
-
```js
25
+
```js
26
26
constbodyParser=require('body-parser');
27
27
require('body-parser-xml')(bodyParser);
28
28
```
29
29
30
30
Once initialised, you can use it just like any other `body-parser` middleware:
31
31
32
-
```js
32
+
```js
33
33
constapp=require('express')();
34
34
app.use(bodyParser.xml());
35
35
```
@@ -48,7 +48,7 @@ If you need to match against a custom `Content-Type` header, pass in the `type`
48
48
49
49
You can also pass in options:
50
50
51
-
```js
51
+
```js
52
52
app.use(bodyParser.xml(options));
53
53
```
54
54
@@ -68,7 +68,7 @@ Controls the maximum request body size. If this is a number, then the value spec
68
68
69
69
#### type
70
70
71
-
The type option is used to determine what media type the middleware will parse. This option can be a string, array of strings, or a function. If not a function, type option is passed directly to the type-is library and this can be an extension name (like xml), a mime type (like application/xml), or a mime type with a wildcard (like */* or */xml). If a function, the type option is called as fn(req) and the request is parsed if it returns a truthy value. Defaults to `['*/xml', '+xml']`.
71
+
The type option is used to determine what media type the middleware will parse. This option can be a string, array of strings, or a function. If not a function, type option is passed directly to the type-is library and this can be an extension name (like xml), a mime type (like application/xml), or a mime type with a wildcard (like _/_ or _/xml). If a function, the type option is called as fn(req) and the request is parsed if it returns a truthy value. Defaults to `['_/xml', '+xml']`.
72
72
73
73
#### verify
74
74
@@ -80,30 +80,31 @@ This option controls the behaviour of the XML parser. You can pass any option th
80
80
81
81
## Example
82
82
83
-
```js
83
+
```js
84
84
constexpress=require('express');
85
85
constbodyParser=require('body-parser');
86
86
87
87
require('body-parser-xml')(bodyParser);
88
88
89
89
constapp=express();
90
-
app.use(bodyParser.xml({
91
-
limit:'1MB', // Reject payload bigger than 1 MB
92
-
xmlParseOptions: {
93
-
normalize:true, // Trim whitespace inside text nodes
94
-
normalizeTags:true, // Transform tags to lowercase
95
-
explicitArray:false// Only put nodes in array if >1
96
-
}
97
-
}));
98
-
99
-
app.post('/users', function(req, res, body) {
90
+
app.use(
91
+
bodyParser.xml({
92
+
limit:'1MB', // Reject payload bigger than 1 MB
93
+
xmlParseOptions: {
94
+
normalize:true, // Trim whitespace inside text nodes
95
+
normalizeTags:true, // Transform tags to lowercase
96
+
explicitArray:false, // Only put nodes in array if >1
0 commit comments