Prompt
When implementing TypeScript code that uses the axum package, maintain consistent and idiomatic usage:
- Always use the lowercase “axum” when referring to the framework, not “Axum”.
- Leverage axum’s built-in types and utilities correctly, such as
Router,Middleware, andRequestBody. - Follow best practices for handling state and dependencies in axum applications, such as using
task_localto pass state between middleware and handlers. - Ensure error handling is properly implemented, with clear and informative error messages returned to clients.
- Use axum’s routing and middleware features effectively to structure your application, avoiding overly complex or nested routing.
Example of correct axum usage in TypeScript:
```typescript import { Router, RequestBody } from ‘@awslabs/aws-lambda-typescript-runtime’;
const router = new Router();
router.get(‘/’, (req) => { return { message: ‘Hello, axum!’ }; });
router.post(‘/users’, async (req: RequestBody<{ name: string }>) => { const { name } = req.body; // Handle user creation logic here return { id: 1, name }; });
export default router;