An async Rust REST API backend using Warp, Diesel, Postgres, and JWT that adheres to the RealWorld spec and API.
Includes real world examples for CRUD operations, authentication, routing, and pagination.
For more information on how this works with various frontends, head over to the RealWorld repo.
Originally forked from https://github.com/colinbankier/realworld-tide.
- Install the Diesel CLI with the
postgres
feature enabled. - Start a postgres database by running
docker-compose up -d
(requiresdocker-compose
) or use your own method. - Copy
.env.example
to.env
and change any environment variables accordingly to your system. - Setup the database by running
diesel database setup
. - When you are done, stop the database with
docker-compose stop
.
The URL of the API will be the value of BIND_ADDRESS
in .env
along with /api
, e.g. https://127.0.0.1:8088/api
.
To test the API, RealWorld provides a Postman collection that we can use.
To run the tests, do the following:
git clone https://github.com/gothinkster/realworld
cd realworld/api
APIURL=http://localhost:8088/api ./run-api-tests.sh
We use JWT to comply with the RealWorld specification, however in practice you should not use JWT for session management. Instead you should use persistent or session cookies with server-side session management.
For reference: Stop Using JWT for sessions and why your solution doesn't work.
Currently, r2d2 and Diesel are both synchronous.