Code for the tutorial
sudo apt update sudo apt install mongodb-org
Check if mongodb is healthy
service mongodb status
echo -e "MONGO_ADDR=localhost DB_NAME=rustlang-rocket-mongodb MONGO_PORT=27017" > .env
rustup default nightly # Pear requires a nightly or dev version of Rustcargo run & # POST curl -d '{"name": "chichi"}' -H "Content-Type: application/json" -X POST http://localhost:8001/cats # Or curl -d '{"name": "chacha", "age": 12, "color": "grey"}' \ -H "Content-Type: application/json" -X POST http://localhost:8001/cats # Or empty curl -d '{}' -H "Content-Type: application/json" -X POST http://localhost:8001/cats # PUT curl -d '{"$oid": "5db15a686539303d5708901f", "name": "chichi"}' -H "Content-Type: application/json" \ -X PUT http://localhost:8001/cats/5db15a686539303d5708901f # GET curl http://localhost:8001/cats # Find by id curl http://localhost:8001/cats/5db15a1f6539303d5708901e # DELETE curl -H "Content-Type: application/json" -X DELETE http://localhost:8001/cats/5db15a1f6539303d5708901e # DELETE all curl -H "Content-Type: application/json" -X DELETE http://localhost:8001/cats
To avoid running parallel tests we use --test-threads=1 because we modify database, otherwise tests would fail.
cargo test -- --test-threads=1