This is a little REST server built with Rocket, Toql and MySQL.
The server allows to call CRUD functions on a Todo
item.
It demonstrates how easy it is to write REST backends with the Rust programming language.
You need a running MySQL server to play around with it.
Then create the database todo_rotomy
and insert the Todo
table with
CREATE TABLE `Todo` (`id` int(11) NOT NULL AUTO_INCREMENT,`title` varchar(200) NOT NULL, `completed` tinyint(1) DEFAULT 0, PRIMARY KEY (`id`))`
Now clone this repository
git clone https://github.com/roy-ganz/todo_rotomy.git
Run the server with your database username and password
ROCKET_DATABASES='{todo_rotomy={url=mysql://USER:PASS@localhost:3306/todo_rotomy}}' cargo run
Open another terminal and use curl
:
curl localhost:8000/todo -X POST -d '{\"title\":\"Water plants\"}'
curl localhost:8000/todo/ID -X PUT -d '{\"completed\":\"true\"}'
curl localhost:8000/todo
curl localhost:8000/todo/ID
curl localhost:8000/todo?query=-id,completed+eq+1
curl -X DELETE localhost:8000/todo/ID
This project may also serve as a starting point for your own REST server.
However if you plan a big project, it's important to split up your Rust
project into separate crates to keep compilation time sane.
The #[derive(Toql)
adds a lot of code to your structs.
Todo-rotomy is distributed under the terms of both the MIT license and the Apache License (Version 2.0).