Skip to content

Commit 5f0fee6

Browse files
Merge pull request drasi-project#34 from agentofreality/feature-lib-api-version
Added versioned API support to Drasi Server
2 parents 1c0936f + 0157212 commit 5f0fee6

40 files changed

Lines changed: 1566 additions & 912 deletions

CLAUDE.md

Lines changed: 50 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ This repository contains only the server wrapper functionality:
3535

3636
1. **Server** (`src/server.rs`) - Main server implementation that wraps DrasiLib
3737
2. **API** (`src/api/`) - REST API implementation with OpenAPI documentation
38+
- `v1/` - API version 1 handlers, routes, and OpenAPI spec
39+
- `shared/` - Common handlers, error types, and response types shared across versions
40+
- `version.rs` - API version constants and utilities
41+
- `models/` - Data Transfer Objects (DTOs)
42+
- `mappings/` - DTO to domain model conversions
3843
3. **Builder** (`src/builder.rs`) - Builder pattern for server construction
3944
4. **Main** (`src/main.rs`) - CLI entry point for standalone server
4045

@@ -146,7 +151,7 @@ instances:
146151
reactions: []
147152
```
148153

149-
The REST API is exposed under `/instances/{instanceId}/...` for multi-instance access; the first configured instance also remains available on the legacy root routes for backward compatibility.
154+
The REST API is exposed under `/api/v1/instances/{instanceId}/...` for multi-instance access; the first configured instance is also accessible via convenience routes at `/api/v1/sources`, `/api/v1/queries`, and `/api/v1/reactions`.
150155

151156
**Important**: Sources and reactions are plugins that must be provided programmatically or via the configuration file's tagged enum format. Queries can also be defined via configuration files.
152157

@@ -238,19 +243,52 @@ server.run().await?;
238243

239244
## API Endpoints
240245

241-
The server exposes a REST API on port 8080 by default:
246+
The server exposes a versioned REST API on port 8080 by default. All API endpoints use URL-based versioning with the `/api/v1/` prefix.
242247

243-
- `GET /health` - Health check
244-
- `GET /openapi.json` - OpenAPI specification
245-
- `GET /swagger-ui/` - Interactive API documentation
248+
### API Versioning
246249

247-
Component management:
248-
- `GET/POST /api/sources` - Source CRUD operations
249-
- `GET/POST /api/queries` - Query CRUD operations
250-
- `GET/POST /api/reactions` - Reaction CRUD operations
251-
- `POST /api/{component}/{id}/start` - Start component
252-
- `POST /api/{component}/{id}/stop` - Stop component
253-
- `GET /api/queries/{id}/results` - Get query results
250+
- `GET /health` - Health check (unversioned operational endpoint)
251+
- `GET /api/versions` - List available API versions
252+
- `GET /api/v1/openapi.json` - OpenAPI specification for v1
253+
- `GET /api/v1/docs/` - Interactive Swagger UI documentation
254+
255+
### Instance Management
256+
257+
- `GET /api/v1/instances` - List all DrasiLib instances
258+
259+
### Component Management (Instance-Specific)
260+
261+
Sources:
262+
- `GET /api/v1/instances/{instanceId}/sources` - List sources
263+
- `POST /api/v1/instances/{instanceId}/sources` - Create source
264+
- `GET /api/v1/instances/{instanceId}/sources/{id}` - Get source status
265+
- `DELETE /api/v1/instances/{instanceId}/sources/{id}` - Delete source
266+
- `POST /api/v1/instances/{instanceId}/sources/{id}/start` - Start source
267+
- `POST /api/v1/instances/{instanceId}/sources/{id}/stop` - Stop source
268+
269+
Queries:
270+
- `GET /api/v1/instances/{instanceId}/queries` - List queries
271+
- `POST /api/v1/instances/{instanceId}/queries` - Create query
272+
- `GET /api/v1/instances/{instanceId}/queries/{id}` - Get query config
273+
- `DELETE /api/v1/instances/{instanceId}/queries/{id}` - Delete query
274+
- `POST /api/v1/instances/{instanceId}/queries/{id}/start` - Start query
275+
- `POST /api/v1/instances/{instanceId}/queries/{id}/stop` - Stop query
276+
- `GET /api/v1/instances/{instanceId}/queries/{id}/results` - Get query results
277+
278+
Reactions:
279+
- `GET /api/v1/instances/{instanceId}/reactions` - List reactions
280+
- `POST /api/v1/instances/{instanceId}/reactions` - Create reaction
281+
- `GET /api/v1/instances/{instanceId}/reactions/{id}` - Get reaction status
282+
- `DELETE /api/v1/instances/{instanceId}/reactions/{id}` - Delete reaction
283+
- `POST /api/v1/instances/{instanceId}/reactions/{id}/start` - Start reaction
284+
- `POST /api/v1/instances/{instanceId}/reactions/{id}/stop` - Stop reaction
285+
286+
### Convenience Routes (First Instance)
287+
288+
For convenience, the first configured instance is accessible via shortened routes:
289+
- `GET/POST /api/v1/sources` - Sources of the first instance
290+
- `GET/POST /api/v1/queries` - Queries of the first instance
291+
- `GET/POST /api/v1/reactions` - Reactions of the first instance
254292

255293
## Important Patterns
256294

Cargo.lock

Lines changed: 19 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)