This example demonstrates the ras-rest-macro OpenAPI output and a minimal
TypeScript usage sample that calls a generated fetch client directly.
rest-api/- Shared API definitions using therest_service!macrorest-backend/- Axum backend implementation with OpenAPI generationtypescript-example/- Minimal TypeScript usage sample for a generated client
- Type-safe API definitions with Rust as the source of truth
- OpenAPI 3.0 document generation from the REST macro
- TypeScript usage sample for a generated fetch client with typed request bodies and responses
- Bearer-token headers for protected endpoints
From the repository root:
cargo check -p rest-backend --lockedThis writes the OpenAPI document consumed by TypeScript client generators.
typescript-example/src/example.ts shows how the generated fetch client is used.
To exercise the calls manually, run the backend:
cargo run -p rest-backend --lockedThe server listens at http://localhost:3000, with API endpoints under
/api/v1/* and OpenAPI docs at /api/v1/docs.
GET /api/v1/users- Get all usersGET /api/v1/users/{id}- Get user by ID
POST /api/v1/users- Create user (admin only)PUT /api/v1/users/{id}- Update user (admin only)DELETE /api/v1/users/{id}- Delete user (admin only)GET /api/v1/users/{user_id}/tasks- Get user tasksPOST /api/v1/users/{user_id}/tasks- Create taskPUT /api/v1/users/{user_id}/tasks/{task_id}- Update taskDELETE /api/v1/users/{user_id}/tasks/{task_id}- Delete task
The example backend uses simple mock tokens:
validtokenfor user permissionsadmintokenfor admin permissions
The generated client accepts ordinary request headers:
const response = await getUsersUserIdTasks({
baseUrl: 'http://localhost:3000/api/v1',
headers: {
Authorization: 'Bearer validtoken',
},
path: { user_id: '123' },
});See typescript-example/src/example.ts for public, admin, and
user-protected calls.