An implementation of the RealWorld API spec in Rust using the Pavex framework
This codebase was created to demonstrate a fully fledged backend application built with Rust and Pavex including CRUD operations, authentication, routing, pagination, and more.
You can exercise the application using Realworld's Postman collection: here.
For more information on how this works with other frontends/backends, head over to the RealWorld website.
- Rust (see here for instructions)
- Docker (see here for instructions)
- Postgres (see here for instructions)
cargo-px
:cargo install cargo-px
pavex_cli
:cd ../../libs && cargo build --release -p pavex_cli
sqlx
CLI:cargo install sqlx-cli \ --no-default-features \ --features native-tls,postgres \ --version 0.7.0-alpha.3
- Launch a local Postgres instance and run SQL migrations:
./scripts/init_db.sh
You are ready to go!
# Add --release if you're looking for maximum performance
cargo px build
APP_PROFILE=dev cargo px run --bin api
All configuration files are in the api_server/configuration
folder.
The default settings are stored in api_server/configuration/base.yml
.
Environment-specific configuration files can be used to override or supply additional values on top the default settings (see prod.yml
).
You must specify the app profile that you want to use by setting the APP_PROFILE
environment variable to either dev
, test
or prod
; e.g.:
APP_PROFILE=prod cargo px run --bin api
All configurable parameters are listed in conduit_core/src/configuration.rs
.
The application uses JWT for authentication, therefore it requires a secret key pair to sign and verify tokens. You can generate one for local development purposes by running:
openssl genpkey -algorithm ed25519 -out private.pem
openssl pkey -in private.pem -pubout -out public.pem
You then need to copy the generated keys to your configuration file, api_server/configuration/dev.yml
for
local development:
# [...]
auth:
eddsa_private_key_pem: |
-----BEGIN PRIVATE KEY-----
# Paste the contents of private.pem here
-----END PRIVATE KEY-----
eddsa_public_key_pem: |
-----BEGIN PUBLIC KEY-----
# Paste the contents of public.pem here
-----END PUBLIC KEY-----