1
0
mirror of https://github.com/actix/examples synced 2025-06-26 17:17:42 +02:00

add guard example

closes #533
This commit is contained in:
Rob Ede
2022-03-05 14:28:43 +00:00
parent c3fd8e1315
commit b8fc58bec6
6 changed files with 123 additions and 1 deletions

34
guards/README.md Normal file
View File

@ -0,0 +1,34 @@
# guards
Shows how to set up custom routing guards.
- Routing different API versions using a header instead of path.
## Usage
### Running The Server
```sh
cd guards
cargo run --bin=guards
```
### Available Routes
#### `GET /api/hello`
Requires the `Accept-Version` header to be present and set to `1` or `2`.
Using [HTTPie]:
```sh
http :8080/api/hello Accept-Version:1
```
Using [cURL]:
```sh
curl 'localhost:8080/api/hello' -H 'accept-version: 1'
```
[HTTPie]: https://httpie.org
[cURL]: https://curl.haxx.se