GitHub repository: pulse-api
Pulse API is a small, containerized Next.js service that exposes basic API routes, records request notes on a persistent Docker volume, and provides a health endpoint for Docker Compose.
├── app
│ ├── api
│ │ ├── health
│ │ │ └── route.ts
│ │ └── notes
│ │ └── route.ts
│ ├── lib
│ │ └── notes.ts
│ ├── layout.tsx
│ └── page.tsx
├── .dockerignore
├── .env.example
├── .gitignore
├── compose.yaml
├── Dockerfile
├── next-env.d.ts
├── next.config.ts
├── package-lock.json
├── package.json
├── README.md
└── tsconfig.json
Deliver a lightweight web API that can be started locally with Docker Compose and used as a foundation for future services.
- Provide
GET /api/healthto report application health. - Provide
GET /api/notesto retrieve stored notes. - Provide
POST /api/notesto create a note with amessagefield. - Persist notes in a mounted Docker volume so they survive container recreation.
- Use Next.js route handlers and Node.js.
- Use a multi-stage Docker build to keep the runtime image small.
- Use Docker Compose for local execution.
- Configure the service through environment variables.
- Add a container health check that calls the health endpoint.
- Run the application as a non-root user in the final image.
| Method | Endpoint | Purpose |
|---|---|---|
GET |
/api/health |
Health status, service name, and timestamp |
GET |
/api/notes |
List persisted notes |
POST |
/api/notes |
Create a note: { "message": "Hello" } |
- Optionally copy the environment file:
Copy-Item .env.example .env - Start the API:
docker compose up --build - Visit
http://localhost:3000/api/health.
The Compose service mounts the named pulse-data volume at /app/data. The API writes its JSON data there, so notes remain after docker compose down and a subsequent up.
| Variable | Default | Description |
|---|---|---|
PORT |
3000 |
Port listened to by the Next.js server |
SERVICE_NAME |
pulse-api |
Name returned by the health endpoint |
DATA_DIR |
/app/data in Docker |
Directory used for persistent note storage |
npm install
npm run devFor local development, set DATA_DIR=./data in .env.local if you want notes saved inside the project folder.
curl http://localhost:3000/api/health
curl -Method Post http://localhost:3000/api/notes -ContentType 'application/json' -Body '{"message":"Container is running"}'
curl http://localhost:3000/api/notes