Skip to content

DocsForYou is a small but production-oriented C++ HTTP service built with Boost.Beast, exposing a minimal REST API to manage text documents on disk. It features layered architecture, Docker support, JSON APIs, and clean separation of concerns. Future improvements include automated tests, improved error responses, and CI workflows.

License

Notifications You must be signed in to change notification settings

alessandrograssi-dev/docsforyou

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

License: MIT C++17 CMake Docker CI

docsforyou

Small C++ HTTP service built with Boost.Beast + CMake.

The project exposes a minimal REST API to store and retrieve text documents on disk.

Why this project is useful

  • Clean separation of concerns: http / services / repository
  • Async HTTP server using Boost.Beast
  • Interface-based persistence (DocumentRepository) with file implementation
  • Easy local build with CMake and Make
  • Dockerized runtime for reproducible runs

Project structure

src/
  http/        # Server, routing, request/response mapping, controllers
  services/    # Business logic (counter, document management)
  repository/  # Persistence abstraction and file implementation
  main.cpp     # Program entrypoint

Requirements

  • Linux/macOS
  • C++17 compiler
  • CMake >= 3.15
  • Boost (system, filesystem)
  • nlohmann/json headers

On Ubuntu/Debian (example):

sudo apt update
sudo apt install -y build-essential cmake libboost-all-dev nlohmann-json3-dev

Build and run (host)

make clean && make
./build/docsforyou 127.0.0.1 8080

API

Base URL:

http://127.0.0.1:8080

1) Health-like counters

  • GET /count → HTML with request counter
  • GET /time → HTML with current epoch time

Example:

curl -i http://127.0.0.1:8080/count
curl -i http://127.0.0.1:8080/time

2) Documents

  • POST /doc creates a document
  • GET /doc/{id} fetches one document
  • DELETE /doc/{id} deletes one document

Create:

curl -i -X POST http://127.0.0.1:8080/doc \
  -H "Content-Type: application/json" \
  -d '{"author":"alice","content":"hello world"}'

Expected response:

{"id":"0"}

Read:

curl -i http://127.0.0.1:8080/doc/0

Delete:

curl -i -X DELETE http://127.0.0.1:8080/doc/0

Docker

Build image:

make docker-build

Run container (maps host 8080 to container 8080):

make docker-run

This command mounts ./data from your host into /app in the container, so *.DFY files persist across restarts.

Stop container:

make docker-stop

Tail logs:

make docker-logs

Override defaults:

make docker-build IMAGE_NAME=docsforyou:v1
make docker-run IMAGE_NAME=docsforyou:v1 CONTAINER_NAME=docsforyou-dev PORT=9090
make docker-run DATA_DIR=$PWD/my-docs-data

Notes

  • Documents are currently stored in the process working directory as *.DFY files.
  • IDs are numeric and generated incrementally.
  • On systems where Docker requires elevated permissions, add your user to the docker group or run Docker commands with sudo.

Suggested next improvements

  • Add automated tests (service and routing layers)
  • Add request validation and consistent JSON error bodies
  • Add configurable data directory via env var or CLI
  • Add CI (build + test) workflow

About

DocsForYou is a small but production-oriented C++ HTTP service built with Boost.Beast, exposing a minimal REST API to manage text documents on disk. It features layered architecture, Docker support, JSON APIs, and clean separation of concerns. Future improvements include automated tests, improved error responses, and CI workflows.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published