Skip to content

Commit

Permalink
Merge pull request #121 from snnair/refine-documentation
Browse files Browse the repository at this point in the history
fix: issue with example URL query string in README.md and added documentation for validating request path parameters
  • Loading branch information
simonplend authored Mar 14, 2024
2 parents 64ddb75 + 1987956 commit 1398af0
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,36 @@ app.post(
```

A valid request must now include a token URL query. Example valid URL:
`/street/?uuid=af3996d0-0e8b-4165-ae97-fdc0823be417`
`/street/?token=af3996d0-0e8b-4165-ae97-fdc0823be417`

The same kind of validation can also be performed on path parameters. Repurposing our earlier example,
we could expect the client to send us the UUID.

```javascript
const pathSchema = {
type: "object",
required: ["uuid"],
properties: {
uuid: {
type: "string",
minLength: 36,
maxLength: 36
},
},
};

app.get(
"/address/:uuid",
validate({ body: addressSchema, params: pathSchema }),
(request, response) => {
/**
* Route handler logic to run when `request.body` and
* `request.params` have both been validated.
*/
response.send({});
}
);
```

## Using dynamic schema

Expand Down

0 comments on commit 1398af0

Please sign in to comment.