# fust **Repository Path**: lxhlxz/fust ## Basic Information - **Project Name**: fust - **Description**: 基于Axum的开发框架,不断完善中 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-06-27 - **Last Updated**: 2024-06-27 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Rust CRUD API Example with Axum Framework and MySQL In this article, you'll discover how to use the Axum framework to build a RESTful API in Rust that supports basic CRUD (Create, Read, Update, Delete) operations against a MySQL database. To achieve this, we'll be leveraging the SQLx toolkit, which provides a simple and efficient way to interact with databases. ![Rust CRUD API Example with Axum Framework and MySQL](https://codevoweb.com/wp-content/uploads/2023/04/Rust-CRUD-API-Example-with-Axum-Framework-and-MySQL.webp) ## Topics Covered - Set up and Run the Axum MySQL CRUD API Project - Run the Axum CRUD API with a Frontend App - Set up the Rust Project - Set up the MySQL Server with Docker - Connect the Axum Server to the MySQL Server - Perform Database Migrations - Define the SQLX Database Model - Define the API Request Structs - Implement the CRUD Functionalities - Route Function to Fetch All Records - Route Function to Insert a Record - Route Function to Retrieve a Record - Route Function to Edit a Record - Route Function to Delete a Record - The Complete Code of the Route Functions - Create an Axum Router for the Route Functions - Register the Axum Router and Set up CORS - Conclusion Read the entire article here: [https://codevoweb.com/rust-crud-api-example-with-axum-framework-and-mysql/](https://codevoweb.com/rust-crud-api-example-with-axum-framework-and-mysql/) 185.199.109.133 # Dependecies ```shell cargo add axum cargo add tokio -F full cargo add tower-http -F "cors" cargo add serde_json cargo add serde -F derive cargo add chrono -F serde cargo add dotenv cargo add uuid -F "serde v4" cargo add sqlx --features "runtime-async-std-native-tls mysql chrono uuid" ``` # Cargo watch ```shell cargo install cargo-watch ``` Once you have Cargo Watch installed, use the command `cargo watch -q -c -w src/ -x run` to start the Axum HTTP server. # Migration ```shell # 安装sqlx-cli cargo install sqlx-cli # 用来创建数据库迁移 sqlx migrate add -r init # 用来运行数据库迁移 sqlx migrate run # 用来回滚数据库迁移 sqlx migrate revert ``` # Run the server ```shell cargo run ``` # TODO: 1. Add logging support 2. Add ORM support 3. Add common controller support for REST 4. Add vallidator 5. docker image 6. install and config mysql for deploy for commit