When implementing TypeScript code that uses the axum package, maintain consistent and idiomatic usage: always use lowercase 'axum', leverage axum's built-in types correctly, follow best practices for state and dependencies, ensure proper error handling, and use routing and middleware features effectively.
When implementing TypeScript code that uses the axum package, maintain consistent and idiomatic usage:
Router
, Middleware
, and RequestBody
.task_local
to pass state between middleware and handlers.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;
Enter the URL of a public GitHub repository