Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

About

Simple REST API with Rust, Rocket and Mongodb

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

AltStyle によって変換されたページ (->オリジナル) /