Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/louis030195/rustlang-rocket-mongodb
Simple REST API with Rust, Rocket and Mongodb
https://github.com/louis030195/rustlang-rocket-mongodb
api mongodb rocket rust rust-lang web web-dev web-development
Last synced: about 1 month ago
JSON representation
Simple REST API with Rust, Rocket and Mongodb
- Host: GitHub
- URL: https://github.com/louis030195/rustlang-rocket-mongodb
- Owner: louis030195
- License: mit
- Created: 2019-10-24T12:27:58.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2019-10-24T12:37:15.000Z (about 5 years ago)
- Last Synced: 2024-09-27T07:22:47.171Z (about 2 months ago)
- Topics: api, mongodb, rocket, rust, rust-lang, web, web-dev, web-development
- Language: Rust
- Size: 6.84 KB
- Stars: 29
- Watchers: 4
- Forks: 10
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# rustlang-rocket-mongodb
[![Try it on gitpod](https://img.shields.io/badge/try-on%20gitpod-brightgreen.svg)](https://gitpod.io/#https://github.com/louis030195/rustlang-rocket-mongodb)Code for the [tutorial](https://medium.com/@louis.beaumont/rest-api-with-rust-mongodb-10eeb6bd51d7)
## Installation
```bash
sudo apt update
sudo apt install mongodb-org
```Check if mongodb is healthy
```bash
service mongodb status
```## Usage
```bash
echo -e "MONGO_ADDR=localhost
DB_NAME=rustlang-rocket-mongodb
MONGO_PORT=27017" > .env
``````bash
rustup default nightly # Pear requires a nightly or dev version of Rust
``````bash
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.
```rust
cargo test -- --test-threads=1
```