Bookstore
BookStore Management REST API Server in Rust with Rocket, SeaORM and JWT.
Project Details
📕 BookStore
BookStore Management REST API Server in Rust with Rocket, SeaORM and JWT.
Udemy Course
Learn about creating this in my Udemy course: Creating an API server in Rust with Rocket, SeaORM and JWT by Afaan Bilal.
Author: Afaan Bilal
Run with Docker 
docker run --rm -it -p 8000:8000 \
-e ROCKET_ADDRESS=0.0.0.0 \
-e BOOKSTORE_JWT_SECRET=[RANDOM SECRET] \
-e BOOKSTORE_DB_HOST=host.docker.internal \
-e BOOKSTORE_DB_PORT=3306 \
-e BOOKSTORE_DB_USERNAME=[DB USERNAME] \
-e BOOKSTORE_DB_PASSWORD=[DB PASSWORD] \
afaanbilal/bookstore
Configuration
The following environment variables configure the server.
| Environment Variable | Default value | Description |
|---|---|---|
| BOOKSTOREJWTSECRET | [none] | The JWT signing secret. Must be set. |
| BOOKSTOREDBHOST | localhost | Database Host |
| BOOKSTOREDBPORT | 3306 | Database Port |
| BOOKSTOREDBUSERNAME | root | Database Username |
| BOOKSTOREDBPASSWORD | [blank] | Database Password |
| BOOKSTOREDBDATABASE | bookstore | Database Name |
| ROCKET_ADDRESS | 127.0.0.1 | HTTP Server Bind Address |
| ROCKET_PORT | 8000 | HTTP Server Port |
Run
cargo run
API

| Method | Path | Auth? | Description |
|---|---|---|---|
| GET | / | ⬜ | Index. Returns Hello, World!. |
| POST | /auth/sign-up | ⬜ | Create a new account. |
| POST | /auth/sign-in | ⬜ | Sign in. Returns a JWT on success. |
| GET | /auth/me | ✅ | Get the authenticated user's details. |
| GET | /authors | ✅ | Get a list of authors. |
| POST | /authors | ✅ | Create an author. |
| GET | /authors/{id} | ✅ | Get the author with matching the id. |
| PUT | /authors/{id} | ✅ | Update the author matching the id. |
| DELETE | /authors/{id} | ✅ | Delete the author matching the id. |
| GET | /authors/{id}/books | ✅ | Get a list of books by the author matching the id. |
| GET | /books | ✅ | Get a list of books. |
| POST | /books | ✅ | Create a book. |
| GET | /books/{id} | ✅ | Get the book with matching the id. |
| PUT | /books/{id} | ✅ | Update the book matching the id. |
| DELETE | /books/{id} | ✅ | Delete the book matching the id. |
Authentication Flow

- All auth required requests: Add header
tokenwith the JWT as the value. - Token lifetime: 4 hours.
Database Structure

Test
cargo test
Entity Generation
sea generate entity -o src/entities -u mysql://root:@localhost:3306/bookstore
Contributing
All contributions are welcome. Please create an issue first for any feature request
or bug. Then fork the repository, create a branch and make any changes to fix the bug
or add the feature and create a pull request. That's it!
Thanks!
License
Bookstore is released under the MIT License.
Check out the full license here.
License
MIT License
Copyright (c) 2023 Afaan Bilal
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.