Rust/Axum server implementation with PCR(Prisma Client Rust)

Overview

Realworld Rust

Realworld Rust Axum Prisma

This project utilizes Rust with the Axum v0.7 framework along with the Prisma Client Rust to build a realworld application. For Prisma Client Rust ORM, refer to Prisma and Prisma Client Rust Repository for more information.

Prerequisites

Make sure you have the following installed:

  • Rust
  • Docker
  • MySQL

Getting Started

Installation

  1. Clone this repository.
  2. Set up your environment variables by creating a .env file in the root directory. Use the provided examples in the README as a guide.
  3. Ensure your MySQL server is running.
  4. Apply migrations
  5. Generate Prisma Client

If you want to use other databases, you need to change the database URL in the .env file and change database provider in schema.prisma file. For more information check out Docs.

Running the Application

You can use the provided justfile for various commands:

  • just setup: Apply migrations using prisma-cli.
  • just generate: Generate the Prisma Client using prisma-cli.
  • just run: Run the application using cargo run.
  • just watch: Use cargo watch to automatically reload the application on file changes.
  • just build: Build the application using the development profile.
  • just release: Build the application for release.
  • just test: Run tests using cargo test.

Docker Setup

If you prefer Docker, follow these steps:

  1. Build the Docker image:

    The Dockerfile includes steps to build the project within a Docker container. Particularly, the cargo prisma generate command is used to generate the Prisma Client during the Docker image build process. This command parses the Prisma schema and creates a client tailored to the defined database structure.

    docker-compose build
  2. Start the containers:

    docker-compose up

Environment Variables

Ensure your environment variables are appropriately set. Here are some examples:

  • DATABASE_URL: MySQL database URL.
  • PORT: Port on which the application runs.
  • RUST_LOG: Rust logging level.
  • JWT_SECRET: Secret key for JWT authentication.
  • MYSQL_ROOT_PASSWORD: If using docker-compose make sure to set MySQL root password.

⚠️ Important Note

This project cannot be built in release mode using Rust stable toolchain version 1.7.4 (stable-aarch64-apple-darwin) due to a compilation error with the psl-core library. However, it can be successfully built in debug mode using this toolchain.

Contributing

Contributions are welcome! Feel free to open issues or pull requests.

License

This project is licensed under the MIT License.

You might also like...
The goal of this repository is to have a real world template of a Rust backend using Axum, Diesel, etc.

Axum Diesel Real-World Example A modular Rust backend template based on the Domain-Driven Design (DDD) architecture, utilizing the Axum and Diesel fra

Axum web framework tutorial for beginners.

Axum Tutorial For Beginners Hello web developers! This tutorial will cover how to write simple web applications in rust with axum framework. If you ar

Yew + Axum + blog = Yab

Yew + Axum + blog = Yab

🪪 Session-based user authentication for Axum.

axum-login 🪪 Session-based user authentication for Axum. 🎨 Overview axum-login is a Tower middleware providing session-based user authentication for

Layers, extractors and template engine wrappers for axum based Web MVC applications

axum-template Layers, extractors and template engine wrappers for axum based Web MVC applications Getting started Cargo.toml [dependencies] axum-templ

🔎 Prometheus metrics middleware for Axum

Axum-Prometheus A Prometheus middleware to collect HTTP metrics for Axum applications. axum-prometheus relies on metrics_exporter_prometheus as a back

Provides json/csv/protobuf streaming support for axum

axum streams for Rust Library provides HTTP response streaming support for axum web framework: JSON array stream format JSON lines stream format CSV s

Simple example of axum, sqlx with sqlite and utoipa (swagger) - without auth

axum_crud_api Simple example to learn creating CRUD rest apis in Rust with axum, sqlx with sqlite and utoipa (swagger) - without auth Also shows how t

Heavy Metal Leptos Stack with Tailwind, Axum, Sqlite, and Cargo Leptos

Heavy Metal Stack Leptos stack with Axum, TailwindCSS, and Sqlite This example creates a basic todo app with an Axum backend that uses Leptos' server

Owner
Neo
Neo
axum-serde is a library that provides multiple serde-based extractors and responders for the Axum web framework.

axum-serde ?? Overview axum-serde is a library that provides multiple serde-based extractors / responses for the Axum web framework. It also offers a

GengTeng 3 Dec 12, 2023
Rust server with Axum, GraphQL and SurrealDb

??️ Article on my web Axum server, Async-GraphQl, SurrealDB template Run without any prior setup, DB is in memory: cargo run To use routes other than

null 15 Jun 26, 2023
An adapter to easily allow an Axum server to be run within a Cloudflare worker.

axum-cloudflare-adapter An adapter to easily allow an Axum server to be run within a Cloudflare worker. Usage use worker::*; use axum::{ response

Logan Keenan 4 Feb 28, 2023
An async no_std HTTP server suitable for bare-metal environments, heavily inspired by axum

picoserve An async no_std HTTP server suitable for bare-metal environments, heavily inspired by axum. It was designed with embassy on the Raspberry Pi

Samuel Hicks 81 Oct 7, 2023
Experiments with Rust CRDTs using Tokio web application framework Axum.

crdt-genome Synopsis Experiments with Rust CRDTs using Tokio web application framework Axum. Background Exploring some ideas of Martin Kleppmann, part

dougfort 3 Mar 18, 2022
Demo of Rust and axum web framework

Demo of Rust and axum web framework Demonstration of: Rust: programming language that focuses on reliability and stability. axum: web framework that f

Joel Parker Henderson 115 Dec 29, 2022
Rust Axum+SQLx Sample

rust-axum-sqlx-sample Install git clone https://github.com/web3ten0/rust-axum-sqlx-1.git cd rust-axum-sqlx-1/local docker-compose up -d sh scripts/exe

web3ten0 5 Jul 9, 2022
Rust Axum Full Course code.

Rust Axum Full Course source code. YouTube Full Course: https://youtube.com/watch?v=XZtlD_m59sM&list=PL7r-PXl6ZPcCIOFaL7nVHXZvBmHNhrh_Q MIT OR Apache,

null 27 Apr 19, 2023
JWT Authentication in Rust using Axum Framework

Are you interested in building a secure authentication system for your Rust web application? Look no further than the Axum framework and JSON Web Tokens (JWTs)! Axum is a fast and scalable Rust web framework that provides a reliable and efficient platform for developing microservices and APIs.

CODEVO 16 Jun 11, 2023
This is a simple Api template for Rust ( Axum framework )

Axum-Rust-Rest-Api-Template This project is an open source Rest Api Template built with Rust's Axum framework. Why this project? I have been learning

Thani 20 Jun 16, 2023