Skip to content

Commit

Permalink
docs(example): add headers validation, minor README improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
thisissandipp committed Jun 14, 2024
1 parent 456c9d5 commit f7439e9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ ValidationRule.query(
),
```

##### 🟣 Request Headers Validation
##### 🟢 Request Headers Validation

```dart
ValidationRule.headers(
Expand Down
11 changes: 11 additions & 0 deletions example/request.http
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@ Content-Type: application/json
"gender": "male"
}

### POST /person with invalid Content-Type header
POST http://localhost:8080/person
Content-Type: application/xml

{
"username": "thecodexhub",
"age": 24,
"email": "[email protected]",
"gender": "male"
}

### POST /person with no username and age field
POST http://localhost:8080/person
Content-Type: application/json
Expand Down
5 changes: 5 additions & 0 deletions example/routes/person/_middleware.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ class PersonValidator extends RequestValidator {

@override
List<ValidationRule> validationRules() => [
ValidationRule.headers(
HttpHeaders.contentTypeHeader,
(value) => value == 'application/json',
message: 'The API only works with content type `application/json`.',
),
ValidationRule.body(
'username',
(value) => value is String && value.isNotEmpty,
Expand Down

0 comments on commit f7439e9

Please sign in to comment.