Skip to content

3axap4eHko/rs-todo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Todo API

A simple, layered Todo REST API written in Rust using Actix-web.

Features

  • CRUD operations for Todo items
  • Layered architecture:
    • domain: core models, errors, repository trait
    • app: business logic in TodoService
    • infra: in-memory repository implementation
    • interfaces: HTTP handlers, configuration, and routing
  • Environment-based configuration (PORT, LOG_LEVEL)
  • Logging via env_logger
  • Comprehensive unit tests and HTTP handler tests

Prerequisites

  • Rust toolchain (1.70+)
  • Cargo
  • (Optional) dotenv-cli

Getting Started

  1. Clone the repository

    git clone https://github.com/your-username/todo-api.git
    cd todo-api
  2. Configure environment Copy .env.example to .env and adjust if needed:

    PORT=8080
    LOG_LEVEL=info
  3. Build & run

    cargo run

    The server will start on http://localhost:8080.

API Endpoints

Method Path Description Body
GET / Health check (returns "OK")
GET /todos List all todos
GET /todos/{id} Get a single todo by ID
POST /todos Create a new todo { "title": "..." }
PUT /todos/{id} Update an existing todo { "title": ".", "completed": true }
DELETE /todos/{id} Delete a todo

Project Structure

├── src
│   ├── app            # Business logic
│   ├── domain         # Core models, errors, and repository trait
│   ├── infra          # In-memory repository implementation
│   ├── interfaces     # HTTP handlers, extractors, router, config
│   ├── main.rs        # Server bootstrap
│   └── lib.rs         # Library exports
├── Cargo.toml         # Dependencies & metadata
└── README.md          # This file

Testing

Run the full test suite:

cargo test

API smoke‑tests (api.sh)

The api.sh script uses atac to exercise all endpoints and verify only status codes without printing response bodies.
atac will automatically capture the id field from the last created todo response, and substitute it into any subsequent requests that reference {{TODO_ID}}.

Logging

By default, logs are printed at the level specified by the LOG_LEVEL environment variable. For example:

LOG_LEVEL=debug cargo run

License

Dual-licensed under MIT OR Apache-2.0. See LICENSE for details.

About

A simple, layered Todo REST API written in Rust using Actix-web.

Resources

Stars

Watchers

Forks