Awesome Open Source
Awesome Open Source

Rust - API with Authentication

An example of API written in Rust with the framework, with a JWT Authentication


  1. Configure Rust to satisfy dependencies


  1. First run the migration
    diesel migration run
  2. Compile the code setting the DATABASE_URL environment variable
        export DATABASE_URL=mysql://username:[email protected]/heroes && cargo run



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"


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'


Special thanks to @sean3z for this repo and this tutorial

Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
rust (4,308
api (1,614
web (955
tutorial (936
authentication (451
webservice (41
rocket (20

Find Open Source By Browsing 7,000 Topics Across 59 Categories