https://github.com/caferrari/express-typed-router
A router wrapper with validation and consistent types for express
https://github.com/caferrari/express-typed-router
Last synced: over 1 year ago
JSON representation
A router wrapper with validation and consistent types for express
- Host: GitHub
- URL: https://github.com/caferrari/express-typed-router
- Owner: caferrari
- Created: 2023-05-12T20:12:57.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2023-05-12T20:13:53.000Z (about 3 years ago)
- Last Synced: 2025-02-08T08:47:36.581Z (over 1 year ago)
- Language: JavaScript
- Size: 37.1 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Create a fully typed router to use with Express
## Sample
```typescript:
import { Router } from 'express';
import * as jwt from 'jsonwebtoken';
import { z } from 'zod';
import { NiceRouter } from 'express-typed-router';
const router = NiceRouter(Router());
router.post(
'/login',
{
body: z.object({ username: z.string(), password: z.string() }),
},
async (req, res) => {
// yout authentication logic
const token = jwt.sign({
user: req.body.username
}, 'my secret', {
expiresIn: '1 day',
algorithm: 'HS256',
});
res.json({
token,
});
}
);
export const authRouter = router.toExpress();
```