Skip to content
An example of API written in Rust with the rocket.rs framework, with a JWT Authentication
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
migrations first commit Jul 25, 2018
src Remove all uses of `unwrap` Jul 30, 2018
.gitignore Docker for development Oct 15, 2018
Cargo.lock Docker for development Oct 15, 2018
Cargo.toml first commit Jul 25, 2018
Dockerfile Docker for development Oct 15, 2018
README.md Closes #3 Removed cache header from curl examples in readme Jul 26, 2018
diesel.toml first commit Jul 25, 2018
docker-compose.yml Docker for development Oct 15, 2018

README.md

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
    diesel migration run
  2. Compile the code setting the DATABASE_URL environment variable
        export DATABASE_URL=mysql://username:password@localhost/heroes && cargo run

API

/auth/login

Get a jwt token for the user marcocastignoli

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)

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

You can’t perform that action at this time.