Skip to content

jvr0x/token-tracker-api

Repository files navigation

Token Tracker API

Simple REST API for tracking cryptocurrency tokens, built with TypeScript. For demonstration purposes only.

Tech Stack

  • Runtime: Node.js
  • Framework: Hono
  • Database: PostgreSQL
  • ORM: Drizzle
  • Validation: Zod
  • Testing: Vitest

Project Structure

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

Prerequisites

  • Node.js 18+
  • Docker (for PostgreSQL)

Setup

  1. Install dependencies:

    npm install
  2. 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
  3. Run migrations:

    npm run db:migrate
  4. Start the server:

    npm run dev

API Endpoints

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

Example Requests

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

Scripts

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

Testing

  1. Create test database:

    docker exec token-tracker-db psql -U dev -d postgres -c "CREATE DATABASE token_tracker_test;"
  2. Run migrations on test database:

    DATABASE_URL="postgres://dev:dev@localhost:5433/token_tracker_test" npm run db:migrate
  3. Run tests:

    npm test

API Conventions

  • 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)

About

Simple REST API for tracking cryptocurrency tokens, built with TypeScript. For demonstration purposes only.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors