A simple RESTful API for simulating the card game War, built in Rust using Rocket
- Ensure that you have Rust and Docker installed.
- Run
docker run -p 5432:5432 --name some-postgres -e POSTGRES_PASSWORD=mysecretpassword -d postgres
in order to start a local Postgres database in Docker - Enter the
api
folder and runcargo install sqlx-cli --no-default-features --features rustls,postgres
to install the sqlx cli - Run
sqlx migrate run --database-url postgres://postgres:mysecretpassword@localhost:5432/postgres
insideapi
to initialize the database - Run
cargo run
to start the API - The API should now be running at http://localhost:8000
- Navigate to http://localhost:8000/start to run a game, and to http://localhost:8000/scores to view the scores
The API was implemented in Rust using the Rocket library. Code related to
serving the endpoints and connecting to the database can be found in main.rs
,
while the game implementation rests in war.rs
. The game functions are also
thoroughly covered with unit testing.
Note: In order to avoid infinite loops, the program terminates games that exceed 10,000 rounds, which results in a draw.