Brief, self-contained Rust + Actix Web API used for HNG task deployment examples.
Contents
- Overview — What this project is and what it exposes.
- Prerequisites — Tools required to build and deploy.
- Local development — How to run locally with Cargo.
- Docker — How the image is built and run.
- Deploy to Fly.io — Steps to deploy using
flyctl. - API Endpoints — Routes and example responses.
basi_api is a small Actix Web server exposing a few JSON endpoints under the /api scope. It is intended to be built with Cargo and packaged in Docker for deployment to platforms like Fly.io.
- Rust toolchain (stable). Install via https://rustup.rs
- Docker (for building images locally or on CI)
- flyctl (for deployment to Fly.io) — https://fly.io/docs/hands-on/install-flyctl/
- Git to clone and push changes
- Clone the repo:
git clone git@github.com:0x00whitecode/Basic-Backend-API.git
cd Basic-Backend-API- Run the server locally:
cargo run- The server binds to the
PORTenvironment variable (defaults to8080). Example:
PORT=8080 cargo run- Test endpoints:
curl http://localhost:8080/api/ # welcome message
curl http://localhost:8080/api/health # health check
curl http://localhost:8080/api/yourname # personalized welcomeThis repo includes a multi-stage Dockerfile that builds the Rust binary in a builder image and produces a small runtime image.
Build locally:
docker build -t basi_api:latest .Run the container (exposes port 8080):
docker run -p 8080:8080 -e PORT=8080 basi_api:latestNotes about the Dockerfile:
- Uses a builder stage to compile the release binary.
- Copies the compiled binary into a minimal Debian-based runtime.
- Sets
PORT=8080and exposes8080so platform orchestrators (like Fly) can map ports.
If your build fails with a Cargo edition error, ensure Cargo.toml uses a supported edition (e.g., edition = "2021") and that the builder image provides a sufficiently recent Rust toolchain.
- Install
flyctland authenticate:
flyctl auth login- Create or reuse an app (if you don't have
fly.tomlalready):
flyctl launch --name basic-backend-api --region iad --no-deploy- Build and deploy:
flyctl deployOr to build only and push an image for later deploy or CI:
flyctl deploy --build-onlyFly-specific notes:
- The app reads
PORTfrom the environment and binds to0.0.0.0, which Fly requires for public traffic. - Check or update
fly.tomlto setinternal_port = 8080under[http_service].
GET /api/— Welcome message JSONGET /api/health— Health check JSONGET /api/{name}— Returns an identity message containing{name}
Example response for /api/:
[{"success":"true","message":"welcome to HNG Task 0x0001"}]PORT— Port to bind to (defaults to8080)DATABASE_URL— (optional) If you add Diesel/Postgres usage, set this for DB connectivity.
Feel free to open issues or PRs. Keep changes small and focused; run cargo fmt and ensure the project builds with cargo build --release.
This project does not include a license file. Add one if you plan to make the repo public with a specific license.