An open API service indexing awesome lists of open source software.

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.

Awesome Lists containing this project

README

          

# ๐Ÿš— Rust Simple Web App - Vehicle REST API

![Rust](https://img.shields.io/badge/rust-%23000000.svg?style=for-the-badge&logo=rust&logoColor=white)
![Axum](https://img.shields.io/badge/axum-ff6600?style=for-the-badge&logo=rust&logoColor=white)
![REST API](https://img.shields.io/badge/REST-API-blue?style=for-the-badge)
![Learning](https://img.shields.io/badge/Purpose-Learning-green?style=for-the-badge)

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."*