Postgres Todo App
This article walks you through how you can easily set up a simple to-do app using Rocket and SQLx with PostgresQL.
Description
This example shows how to make a simple TODO app using Rocket and a shared Shuttle Postgres DB.
The following routes are provided:
- GET
/todo/<id>
- Get a to-do item by ID. - POST
/todo
- Create a to-do item. Takes “note” as a JSON body parameter.
You can clone the example below by running the following (you’ll need cargo-shuttle
installed):
shuttle init --from shuttle-hq/shuttle-examples \
--subfolder rocket/postgres
Code
Usage
Once you’ve cloned the example, try launching it locally using shuttle run
. Once you’ve verified that it runs successfully, try using cURL in a new terminal to send a POST request:
curl -X POST -d '{"note":"Hello world!"}' -H 'Content-Type: application/json' \
http://localhost:8000/todo
Assuming the request was successful, you’ll get back a JSON response with the ID and Note of the record you just created. If you try the following cURL command, you should be able to then retrieve the message you stored:
curl http://localhost:8000/todo/<id>
Interested in extending this example? Here’s as couple of ideas:
- Add update and delete routes
- Add static files to show your records
Was this page helpful?