Skip to content

Commit ca87b9c

Browse files
committed
docs: cleanup readme
1 parent 81c9f48 commit ca87b9c

1 file changed

Lines changed: 5 additions & 115 deletions

File tree

README.md

Lines changed: 5 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# api-machine - REST API Server Framework
1+
# API-Machine
22

33
A lightweight, TypeScript-first REST API framework built on Express with a class-based routing architecture.
44

@@ -85,83 +85,17 @@ The [`examples/`](examples/) directory contains comprehensive examples:
8585
- Request body validation
8686
- Structured error responses
8787

88-
## Configuration
89-
90-
### Server Options
91-
#### port `number = 5000`
92-
93-
The port number on which the server will listen for incoming requests.
94-
95-
#### maxPayloadSizeMB `number = 10`
96-
97-
Maximum size in megabytes for JSON request payloads that the server will accept.
98-
99-
#### maxUrlEncodedSizeMB `number = 1`
100-
101-
Maximum size in megabytes for URL-encoded request payloads that the server will accept.
102-
103-
#### log `LogInterface = console`
104-
105-
Custom logger interface for handling server logging (e.g. `ts-tiny-log`). Must implement the LogInterface contract.
106-
107-
#### securityHeaders `SecurityHeadersOptions`
108-
109-
Configuration for HTTP security headers. By default, api-machine is **secure by default** with:
110-
- X-Powered-By header removed (prevents server fingerprinting)
111-
- X-Content-Type-Options: nosniff (prevents MIME sniffing)
112-
- X-Frame-Options: DENY (prevents clickjacking)
113-
- X-XSS-Protection: 1; mode=block (legacy XSS protection)
114-
115-
See **[Security Headers Documentation](docs/security-headers.md)** for detailed configuration options and best practices.
116-
11788
### Example with Options
11889

11990
```typescript
120-
const server = new MyServer({
91+
const server = new MyApiServer({
12192
port: 8080,
12293
maxPayloadSizeMB: 20,
12394
maxUrlEncodedSizeMB: 2,
12495
log: myCustomLogger
12596
});
12697
```
12798

128-
## API Summary
129-
130-
### RestServer
131-
132-
Abstract class for creating REST API servers.
133-
134-
**Methods:**
135-
- `start()`: Starts the server
136-
- `stop()`: Stops the server
137-
138-
139-
### BaseApiRouter
140-
141-
Abstract class for creating route groups.
142-
143-
**Properties:**
144-
- `path`: The base path for the router (e.g., `/api`)
145-
146-
**Methods:**
147-
- `routes()`: Abstract method to define endpoints (must be implemented)
148-
149-
### BaseApiEndpoint
150-
151-
Abstract class for creating API endpoints.
152-
153-
**Properties:**
154-
- `path`: The endpoint path (default: `''`)
155-
- `method`: The HTTP method (default: `GET`). Can be:
156-
- `EndpointMethods.GET`
157-
- `EndpointMethods.POST`
158-
- `EndpointMethods.PATCH`
159-
- `EndpointMethods.PUT`
160-
- `EndpointMethods.DELETE`
161-
162-
**Methods:**
163-
- `handle(request, response, next)`: Abstract method to handle requests (must be implemented)
164-
16599
#### Using Different HTTP Methods
166100

167101
api-machine provides convenience classes for each HTTP method with appropriate default status codes:
@@ -227,55 +161,11 @@ class DeleteUserEndpoint extends DeleteEndpoint {
227161
}
228162
```
229163

230-
**Available Endpoint Classes:**
231-
- `GetEndpoint` - GET requests (200 OK)
232-
- `PostEndpoint` - POST requests (201 Created)
233-
- `PutEndpoint` - PUT requests (200 OK)
234-
- `PatchEndpoint` - PATCH requests (200 OK)
235-
- `DeleteEndpoint` - DELETE requests (204 No Content)
236-
- `HealthCheckEndpoint` - Pre-built health check endpoint (GET /health)
237-
238-
You can also use `BaseApiEndpoint` and manually set the `method` and `statusCode` properties if needed for custom behavior.
239-
240164
#### Pre-Built Endpoints
241165

242166
##### HealthCheckEndpoint
243167

244-
A ready-to-use health check endpoint that returns system status information. Simply include it in your router:
245-
246-
```typescript
247-
import { BaseApiRouter, HealthCheckEndpoint } from 'api-machine';
248-
249-
class MyRouter extends BaseApiRouter {
250-
override path = '/api';
251-
252-
async routes() {
253-
return [
254-
HealthCheckEndpoint, // Available at GET /api/health
255-
// ... other endpoints
256-
];
257-
}
258-
}
259-
```
260-
261-
**Response Format:**
262-
```json
263-
{
264-
"status": "ok",
265-
"timestamp": "2025-11-08T12:00:00.000Z",
266-
"uptime": 123.45,
267-
"environment": "development"
268-
}
269-
```
270-
271-
**Customizing the Path:**
272-
```typescript
273-
class CustomHealthCheck extends HealthCheckEndpoint {
274-
override path = '/status'; // Available at GET /api/status
275-
}
276-
```
277-
278-
For advanced usage, extending the health check with custom checks, and deployment examples (Kubernetes, Docker, monitoring), see the **[Health Check Endpoint Documentation](docs/health-check-endpoint.md)**.
168+
A ready-to-use health check endpoint that returns system status information. Simply include it in your router. For advanced usage, extending the health check with custom checks, and deployment examples (Kubernetes, Docker, monitoring), see the **[Health Check Endpoint Documentation](docs/health-check-endpoint.md)**.
279169

280170
## Error Handling
281171

@@ -303,7 +193,7 @@ class GetUserEndpoint extends GetEndpoint {
303193
```
304194

305195
**Key Features:**
306-
- 29 built-in error classes covering HTTP status codes 400-451
196+
- Built-in error classes covering HTTP status codes 400-451
307197
- Automatic JSON error responses with timestamps
308198
- Support for custom headers (e.g., `WWW-Authenticate`, `Retry-After`)
309199
- Optional `details` field for additional context
@@ -376,7 +266,7 @@ See **[Authentication Documentation](docs/authentication.md)** for complete usag
376266

377267
## Middleware
378268

379-
Routers and endpoints support Express-style middleware for logging, validation, and more. See [Middleware Support](docs/middleware.md) for usage and examples.
269+
Routers and endpoints support Express middleware for logging, validation, and more. See [Middleware Support](docs/middleware.md) for usage and examples.
380270

381271
## Contributing & Development
382272

0 commit comments

Comments
 (0)