Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/marcocastignoli/rust_rocket_api_authentication
An example of API written in Rust with the rocket.rs framework, with a JWT Authentication
https://github.com/marcocastignoli/rust_rocket_api_authentication
api authentication rocket rust tutorial web webservice
Last synced: about 1 month ago
JSON representation
An example of API written in Rust with the rocket.rs framework, with a JWT Authentication
- Host: GitHub
- URL: https://github.com/marcocastignoli/rust_rocket_api_authentication
- Owner: marcocastignoli
- Created: 2018-07-25T10:05:43.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-10-15T17:28:48.000Z (about 6 years ago)
- Last Synced: 2024-09-26T07:21:42.013Z (about 2 months ago)
- Topics: api, authentication, rocket, rust, tutorial, web, webservice
- Language: Rust
- Size: 21.5 KB
- Stars: 122
- Watchers: 6
- Forks: 17
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Rust rocket.rs - API with Authentication
An example of API written in Rust with the rocket.rs framework, with a JWT Authentication
## Requirements
1. Configure Rust to satisfy rocket.rs dependencies
## Installation
1. First run the migration
```bash
diesel migration run
```
2. Compile the code setting the DATABASE_URL environment variable
```bash
export DATABASE_URL=mysql://username:password@localhost/heroes && cargo run
```## API
### /auth/login
Get a jwt token for the user marcocastignoli
```bash
curl -X POST \
http://localhost:8000/auth/login \
-H 'content-type: application/json' \
-d '{
"username": "marcocastignoli",
"password": "12345"
}'
```
### /user
Call a protected route (use the token returned from the /auth/login API)
```bash
curl -X GET \
http://localhost:8000/user \
-H 'authentication: eyJ0eXAiOiJKV1QiLCJraWQiOm51bGwsImFsZyI6IkhTMjU2In0.eyJpc3MiOm51bGwsInN1YiI6Im1hcmNvY2FzdGlnbm9saSIsImF1ZCI6bnVsbCwiZXhwIjpudWxsLCJuYmYiOm51bGwsImlhdCI6bnVsbCwianRpIjpudWxsfQ.fnp0D8Qh1bTFv1zKTVGAxwjtyTCOqKuarRzBQabjiCI'
```## Thanks
Special thanks to @sean3z for this repo https://github.com/sean3z/rocket-diesel-rest-api-example and this tutorial https://medium.com/sean3z/building-a-restful-crud-api-with-rust-1867308352d8