https://github.com/kavinda-100/rust_simple_web_app
A simple REST API built with Rust and the Axum web framework for learning purposes. This project demonstrates basic CRUD operations for vehicle management without database integration.
https://github.com/kavinda-100/rust_simple_web_app
axum backend-api cargo rest-api rust
Last synced: 3 months ago
JSON representation
A simple REST API built with Rust and the Axum web framework for learning purposes. This project demonstrates basic CRUD operations for vehicle management without database integration.
- Host: GitHub
- URL: https://github.com/kavinda-100/rust_simple_web_app
- Owner: kavinda-100
- Created: 2025-07-25T07:19:03.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2025-07-25T08:49:00.000Z (11 months ago)
- Last Synced: 2025-07-25T13:10:03.449Z (11 months ago)
- Topics: axum, backend-api, cargo, rest-api, rust
- Language: Rust
- Homepage:
- Size: 23.4 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ๐ Rust Simple Web App - Vehicle REST API




A simple REST API built with **Rust** and the **Axum** web framework for learning purposes. This project demonstrates basic CRUD operations for vehicle management without database integration.
## ๐ฏ Project Goals
- ๐ Learn Rust programming language fundamentals
- ๐ Understand REST API development with Axum
- ๐ง Practice CRUD operations (Create, Read, Update, Delete)
- ๐ Build a foundation for future Rust web development
## โจ Features
- โ
**GET** - Retrieve all vehicles or specific vehicle by ID
- โ
**POST** - Create new vehicles with auto-generated UUIDs
- โ
**PUT** - Update existing vehicles
- โ
**DELETE** - Remove vehicles by ID
- โ
**Query Parameters** - Search vehicles with custom filters
- โ
**JSON Response** - All endpoints return JSON data
- โ
**HTTP Status Codes** - Proper status codes (200, 201, 204, etc.)
## ๐ ๏ธ Tech Stack
- **Language**: Rust ๐ฆ
- **Web Framework**: Axum
- **Serialization**: Serde (JSON)
- **Async Runtime**: Tokio
- **UUID Generation**: uuid crate
- **HTTP Client Testing**: REST Client files
## ๐ API Endpoints
| Method | Endpoint | Description | Status Code |
|--------|----------|-------------|-------------|
| `GET` | `/` | Welcome message | 200 |
| `GET` | `/vehicle/all` | Get all vehicles | 200 |
| `GET` | `/vehicle/{id}` | Get vehicle by ID | 200 |
| `GET` | `/vehicle/query?params` | Search vehicles | 200 |
| `POST` | `/vehicle` | Create new vehicle | 201 |
| `PUT` | `/vehicle/{id}` | Update vehicle | 200 |
| `DELETE` | `/vehicle/{id}` | Delete vehicle | 204 |
## ๐ Getting Started
### Prerequisites
- [Rust](https://rustup.rs/) (latest stable version)
- [Cargo](https://doc.rust-lang.org/cargo/) (comes with Rust)
### Installation
1. **Clone the repository**
```bash
git clone https://github.com/kavinda-100/rust_simple_web_app.git
cd rust_simple_web_app
```
2. **Install dependencies**
```bash
cargo build
```
3. **Run the server**
```bash
cargo run
```
4. **Server will start on**
```
๐ http://localhost:5000
```
## ๐ Usage Examples
### Using the HTTP File
The project includes a `AxumWithRust.http` file for easy API testing. Open it in VS Code with the REST Client extension or any compatible IDE.
### Sample Requests
#### Create a Vehicle
```http
POST http://localhost:5000/vehicle
Content-Type: application/json
{
"manufacturer": "Toyota",
"name": "Camry",
"model": "Camry",
"year": 2023
}
```
#### Get All Vehicles
```http
GET http://localhost:5000/vehicle/all
```
#### Search Vehicles
```http
GET http://localhost:5000/vehicle/query?manufacturer=Toyota&year=2023
```
#### Update Vehicle
```http
PUT http://localhost:5000/vehicle/1
Content-Type: application/json
{
"manufacturer": "Honda",
"name": "Civic",
"model": "Civic",
"year": 2024
}
```
#### Delete Vehicle
```http
DELETE http://localhost:5000/vehicle/1
```
## ๐ Project Structure
```
rust_simple_web_app/
โโโ ๐ Cargo.toml # Project dependencies
โโโ ๐ README.md # Project documentation
โโโ ๐งช AxumWithRust.http # HTTP test requests
โโโ ๐ src/
โ โโโ ๐ main.rs # Application entry point & routes
โ โโโ ๐ vehicle.rs # Vehicle handlers & data structures
โโโ ๐ target/ # Compiled artifacts
```
## ๐ง Dependencies
```toml
[dependencies]
axum = "0.7"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
tokio = { version = "1.0", features = ["full"] }
uuid = { version = "1.0", features = ["v4"] }
```
## ๐ Learning Objectives Covered
- โ
**Rust Syntax**: Structs, enums, pattern matching, ownership
- โ
**Async Programming**: Understanding `async/await` with Tokio
- โ
**Web Development**: HTTP methods, status codes, JSON handling
- โ
**Error Handling**: Result types and proper error responses
- โ
**Code Organization**: Module system and separation of concerns
- โ
**Testing**: HTTP file-based API testing
## ๐ License
This project is available for learning purposes.
## Author
- [Kavinda Rathnayake](https://github.com/kavinda-100)
## ๐ Acknowledgments
- ๐ฆ [Rust Community](https://www.rust-lang.org/)
- โก [Axum Framework](https://github.com/tokio-rs/axum)
- ๐ [Rust Book](https://doc.rust-lang.org/book/)
- ๐ [Tokio Async Runtime](https://tokio.rs/)
---
**Happy Learning with Rust! ๐ฆโจ**
> *"The best way to learn is by building. Start simple, iterate, and grow."*