- reqwest 0.12 → 0.13, rustls-tls → rustls (golden, Dockerfile, promptit) - Docker volume cache: kipina-cargo-registry + kipina-cargo-target - rust:latest (1.94) + cmake (aws-lc-sys vaatii) - Dockerfile yksinkertaistettu — esikäännös ei toimi, volume hoitaa - Golden example 10/10 testattu uudella setupilla
1.8 KiB
REFERENCE PATTERNS (follow exactly):
STACK: Axum 0.8 + SQLx + SQLite + Tokio + Serde
Cargo.toml: edition = "2024" deps: axum 0.8, tokio (full), serde (derive), serde_json, sqlx (sqlite, runtime-tokio), tower-http (cors) dev: reqwest 0.13 (rustls)
src/models.rs: #[derive(Debug, Serialize, Deserialize, FromRow)] struct Entity { id: i64, field: String, optional: Option } struct CreateEntity { field: String, optional: Option } Status fields: String with default "pending"
src/handlers.rs: async fn create(State(pool), Json(input)) -> (StatusCode, Json) POST → StatusCode::CREATED, sqlx::query("INSERT...").execute + query_as last_insert_rowid GET list → query_as("SELECT * FROM table").fetch_all GET by id → query_as.fetch_optional, return 404 if None PUT → query("UPDATE...SET...WHERE id=?"), rows_affected == 0 → 404 DELETE → StatusCode::NO_CONTENT, rows_affected == 0 → 404
src/lib.rs: pub fn app(pool: SqlitePool) -> Router pub async fn init_db(pool: &SqlitePool) → CREATE TABLE IF NOT EXISTS Routes: .route("/{table}", post(create).get(list)) .route("/{table}/{id}", get(get_one).put(update).delete(delete_one))
src/main.rs: SqlitePool::connect("sqlite:./app.db"), init_db, bind 0.0.0.0:3000
tests/api_test.rs: Each test: SqlitePool::connect("sqlite::memory:"), init_db, app(pool) Spawn on random port: TcpListener::bind("127.0.0.1:0"), axum::serve reqwest::Client for HTTP calls Unique Finnish data ("Osta maitoa", "Haettava tehtävä"...) test_create → 201 + assert id exists test_list → post first, get, assert len >= 1 test_get_by_id → post, get, assert id matches test_not_found → 404 test_update → post, put with ALL fields, assert 200 test_delete → post, delete 204, get → 404