Tutorial: a library API
This tutorial builds a small, complete REST API with rind, one step at a time. If you have followed Django’s “Writing your first Django app” tutorial, the path will feel familiar: create a project, describe the data, serve it over HTTP, open it to users, add some behaviour of your own, and test it.
The application is a library:
- the library has authors and books;
- anyone can read the catalogue, but only librarians can change it;
- signed-in members can borrow a book and give it back;
- members see their own loans, librarians see every loan.
Every command and every answer shown in these pages was really run.
The parts
- Creating a project:
rind new, what it writes, and the firstrind serve. - Models and migrations: authors and books, a foreign
key, and the SQL that
rind makewrites. - A first resource: the
/booksendpoint, its serializer and its input; creating, reading, changing and deleting books withcurl. - Lists: filters, search, ordering, pages: what a client can ask of a list.
- Users and permissions: signing in with
rind-auth, a second domain for the loans, rules, and permission modes. - Actions and tests: a
give_backaction, and a test that runs the whole story over HTTP.
Each part takes between fifteen and thirty minutes.
What you need
- Rust, recent enough for the 2024 edition (
rustup update). - Docker, to run PostgreSQL. Any PostgreSQL server will do if you already have one.
curl, to talk to the API. Any HTTP client works.- A checkout of rind. rind is not published on crates.io yet, so the
rindtool is installed from the repository, and new projects depend on that checkout by its path.
You should be able to read Rust. You do not need to know how macros work:
rind uses derives (#[derive(Model)], #[derive(Resource)]) to write
most of the code for you, and you will only write attributes on structs.
Where to go after
The tutorial shows the common path. Each topic has a chapter of its own that goes into detail: Models, Queries, Resources, Serializers, Inputs, Filters, Permissions, and the others in the table of contents. rind for Django developers maps the Django names you know to the rind ones.