Rocket MVC
A REST web application build in Rust. It use Rocket & Diesel.
This sample just an API who allow you to edit recipes according to REST conventions.
- List recipes: GET /recipes
- Create recipes: POST /recipes
- Show recipe: GET /recipes/<recipe_id>
- Edit recipe: GET /recipes/<recipe_id>/edit
- Delete recipe: DELETE /recipes/<recipe_id>
Instalation
First you need to install Rust. Then Clone the repository and go in the folder
$ git clone https://github.com/madeindjs/Rocket_MVC.git
$ cd Rocket_MVC
According to Rocket, you need to use Nightly version of Rust
$ rustup override set nightly
Then install diesel_cli and run database migrations
$ cargo install diesel_cli --no-default-features --features sqlite
$ diesel setup
And now you can build project
$ cargo run
Example
This is an example with cURL.
- First, create a recipe
$ curl -X POST 'http://localhost:8000/recipes' -d 'name=from_curl'
- Check if created
$ curl -X GET 'http://localhost:8000/recipes'
[{"id":1,"name":"from_curl"}]
- Update it
$ curl -X PUT 'http://localhost:8000/recipes/1' -d 'name=update_from_curl'
$ curl -X GET 'http://localhost:8000/recipes/1'
{"id":1,"name":"update_from_curl"}
- Destroy record
$ curl -X DELETE 'http://localhost:8000/recipes/1'
Benchmark
TODO