Giter VIP home page Giter VIP logo

bookstore's Introduction

๐Ÿ“• 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

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
BOOKSTORE_JWT_SECRET [none] The JWT signing secret. Must be set.
BOOKSTORE_DB_HOST localhost Database Host
BOOKSTORE_DB_PORT 3306 Database Port
BOOKSTORE_DB_USERNAME root Database Username
BOOKSTORE_DB_PASSWORD [blank] Database Password
BOOKSTORE_DB_DATABASE bookstore Database Name
ROCKET_ADDRESS 127.0.0.1 HTTP Server Bind Address
ROCKET_PORT 8000 HTTP Server Port

Run

cargo run

API

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

Authentication Flow

  • All auth required requests: Add header token with the JWT as the value.
  • Token lifetime: 4 hours.

Database Structure

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.

bookstore's People

Contributors

afaanbilal avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.