Member-only story
Build API with Rust and Dockerize
Dockerize API with Actix Web
3 min readOct 16, 2023
“Actix Web is a powerful, pragmatic, and extremely fast web framework for Rust”
Actix is one of the web frameworks build in rust and i think this framework easy to use. this article will help you to build api expenses with actix that can get list and set the list without database (using database and CRUD complete cooming soon).
Step 1: Init App
cargo new expenses-api
cd expenses-api
Step 2: Add Dependency
Edit Cargo.toml
- Add Binary target settings to set executable programs that can be run after being compiled
2. Add dependency actix-web
, serde
, lazy_static
[[bin]]
name = "expenses-api"
path = "src/main.rs"
[dependencies]
actix-web = "4"
serde = { version = "1.0.186", features = ["derive"]}
lazy_static = "1.4"
Step 3: Define Model
1. Create new file inside /src/models/expenses.rs
2. Define struct for Expenses
use serde::{Deserialize, Serialize};
#[derive(Deserialize, Serialize, Clone)]
pub struct Expenses {
pub date: String,
pub item…