Skip to content

Commit 1398af0

Browse files
authored
Merge pull request #121 from snnair/refine-documentation
fix: issue with example URL query string in README.md and added documentation for validating request path parameters
2 parents 64ddb75 + 1987956 commit 1398af0

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

README.md

+30-1
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,36 @@ app.post(
211211
```
212212

213213
A valid request must now include a token URL query. Example valid URL:
214-
`/street/?uuid=af3996d0-0e8b-4165-ae97-fdc0823be417`
214+
`/street/?token=af3996d0-0e8b-4165-ae97-fdc0823be417`
215+
216+
The same kind of validation can also be performed on path parameters. Repurposing our earlier example,
217+
we could expect the client to send us the UUID.
218+
219+
```javascript
220+
const pathSchema = {
221+
type: "object",
222+
required: ["uuid"],
223+
properties: {
224+
uuid: {
225+
type: "string",
226+
minLength: 36,
227+
maxLength: 36
228+
},
229+
},
230+
};
231+
232+
app.get(
233+
"/address/:uuid",
234+
validate({ body: addressSchema, params: pathSchema }),
235+
(request, response) => {
236+
/**
237+
* Route handler logic to run when `request.body` and
238+
* `request.params` have both been validated.
239+
*/
240+
response.send({});
241+
}
242+
);
243+
```
215244

216245
## Using dynamic schema
217246

0 commit comments

Comments
 (0)