Skip to content

louis030195/rustlang-rocket-mongodb

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rustlang-rocket-mongodb

Try it on gitpod

Code for the tutorial

Installation

sudo apt update
sudo apt install mongodb-org

Check if mongodb is healthy

service mongodb status

Usage

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 Rust
cargo 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

Tests

To avoid running parallel tests we use --test-threads=1 because we modify database, otherwise tests would fail.

cargo test -- --test-threads=1

Releases

No releases published

Packages

No packages published

Languages