Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OddNet Manager API

A simple TypeScript REST API for managing OddNet data with direct CRUD operations on PostgreSQL.

Features

  • 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

Tech Stack

  • Runtime: Node.js with TypeScript
  • Framework: Express
  • Database: PostgreSQL with TypeORM
  • Modules: ES2022

Setup

Prerequisites

  • Node.js (v18 or later)
  • PostgreSQL (v13 or later)

Installation

  1. Install dependencies:
npm install
  1. Create your environment file:
cp .env.example .env
  1. Edit .env with your database credentials and API key

  2. Create the database:

createdb oddnet_manager
  1. Run migrations:
npm run migration:run

Development

Start the development server with hot reload:

npm run dev

Production

Build and start the production server:

npm run build
npm start

API Endpoints

All endpoints require Authorization: Bearer <API_KEY> header except /health.

Health Check

  • GET /health - Returns server status (no auth required)

Identities

  • GET /api/identities - List all identities
  • GET /api/identities/:id - Get one identity by UUID
  • POST /api/identities - Create new identity
  • PUT /api/identities/:id - Update identity (full replacement)
  • DELETE /api/identities/:id - Delete identity

Example: Create 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"
  }'

Database Migrations

# 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:show

Project Structure

src/
├── 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

License

Apache-2.0

About

management api for oddnet agent data

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages