Simple REST API for tracking cryptocurrency tokens, built with TypeScript. For demonstration purposes only.
src/
├── index.ts # Server entry point
├── app.ts # Hono app configuration
├── db/
│ ├── index.ts # Database connection
│ └── schema.ts # Drizzle table definitions
├── routes/
│ ├── tokens.ts # Token CRUD endpoints
│ └── health.ts # Health check endpoint
├── schemas/
│ └── token.ts # Zod validation schemas
└── serializers/
└── token.ts # Response transformers
tests/
├── setup.ts # Test database setup
├── schemas/ # Unit tests for validation
├── serializers/ # Unit tests for serializers
└── routes/ # Integration tests
- Node.js 18+
- Docker (for PostgreSQL)
-
Install dependencies:
npm install
-
Start PostgreSQL:
docker run --name token-tracker-db \ -e POSTGRES_USER=dev \ -e POSTGRES_PASSWORD=dev \ -e POSTGRES_DB=token_tracker \ -p 5433:5432 \ -d postgres:16
-
Run migrations:
npm run db:migrate
-
Start the server:
npm run dev
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/tokens |
List all tokens |
| GET | /api/tokens/:id |
Get token by ID |
| POST | /api/tokens |
Create a token |
| PUT | /api/tokens/:id |
Update a token |
| DELETE | /api/tokens/:id |
Delete a token |
| GET | /health |
Health check |
Create a token:
curl -X POST http://localhost:3000/api/tokens \
-H "Content-Type: application/json" \
-d '{"symbol": "btc", "name": "Bitcoin", "price_usd": 9000000000000}'List tokens:
curl http://localhost:3000/api/tokens| Command | Description |
|---|---|
npm run dev |
Start server with hot reload |
npm run start |
Start server |
npm run test |
Run all tests |
npm run test:watch |
Run tests in watch mode |
npm run fmt |
Format code with Prettier |
npm run db:generate |
Generate migrations from schema |
npm run db:migrate |
Apply migrations |
npm run db:studio |
Open Drizzle Studio |
-
Create test database:
docker exec token-tracker-db psql -U dev -d postgres -c "CREATE DATABASE token_tracker_test;"
-
Run migrations on test database:
DATABASE_URL="postgres://dev:dev@localhost:5433/token_tracker_test" npm run db:migrate -
Run tests:
npm test
- Request/response bodies use snake_case (e.g.,
price_usd) - Internal TypeScript code uses camelCase (e.g.,
priceUsd) - Prices are stored as integers with 8 decimal places (e.g., $90,000.00 =
9000000000000)