A simple TypeScript REST API for managing OddNet data with direct CRUD operations on PostgreSQL.
- Simple Authentication: API key-based authentication (no user roles)
- Direct Database Access: Immediate read/write operations without computation
- Migration-Based Schema Management: TypeORM migrations for version control
- Full CRUD Operations: Every entity supports Create, Read, Update, and Delete
- Runtime: Node.js with TypeScript
- Framework: Express
- Database: PostgreSQL with TypeORM
- Modules: ES2022
- Node.js (v18 or later)
- PostgreSQL (v13 or later)
- Install dependencies:
npm install- Create your environment file:
cp .env.example .env-
Edit
.envwith your database credentials and API key -
Create the database:
createdb oddnet_manager- Run migrations:
npm run migration:runStart the development server with hot reload:
npm run devBuild and start the production server:
npm run build
npm startAll endpoints require Authorization: Bearer <API_KEY> header except /health.
GET /health- Returns server status (no auth required)
GET /api/identities- List all identitiesGET /api/identities/:id- Get one identity by UUIDPOST /api/identities- Create new identityPUT /api/identities/:id- Update identity (full replacement)DELETE /api/identities/:id- Delete identity
curl -X POST http://localhost:3000/api/identities \
-H "Authorization: Bearer your_api_key" \
-H "Content-Type: application/json" \
-d '{
"knownAs": "Alice",
"fullName": "Alice Johnson",
"pronouns": "she/her",
"species": "human"
}'# Generate migration from entity changes
npm run migration:generate src/database/migrations/DescriptionOfChange
# Create empty migration
npm run migration:create src/database/migrations/DescriptionOfChange
# Run pending migrations
npm run migration:run
# Revert last migration
npm run migration:revert
# Show migration status
npm run migration:showsrc/
├── main.ts # Application entry point
├── database/
│ ├── dataSource.ts # TypeORM configuration
│ ├── entities/ # Entity definitions
│ └── migrations/ # Database migrations
├── middleware/
│ ├── auth.ts # API key authentication
│ └── errorHandler.ts # Global error handling
├── routes/ # Route definitions
└── controllers/ # Business logic
Apache-2.0