__ _
/ _) / \ /\ /\
/(_)( \_/ / \/ \
(____)\ _ ___/ /\ \
U (_) (___/ \/ /
_ _ \_ /
(____(__ \_____/
Raptur Router is a simple, TypeScript-first HTTP router for Node.js. Built with developer experience in mind, it provides a clean, chainable API for building web applications.
- π Simple routing
- πͺ Built with TypeScript
- π― Type safety
- β‘οΈ Async/await support
- π URL parameter parsing
- π¦ Zero dependencies
- π Chainable API
- π¦ Prehistoric power!
Still WIP so not on npm yet.
npm install raptur
import { Raptur } from 'raptur';
const app = new Raptur(); // can pass optional port, default is :3000
app
.get('/api/hello', (req, res) => {
res.json({ message: 'Hello from Raptur! π¦' });
})
.get('/api/users/:id', async (req, res) => {
const { id } = req.params;
res.json({ userId: id });
})
.post('/api/users', async (req, res) => {
const body = await req.json();
res.status(201).json({ message: 'User created', data: body });
});
app.start(() => {
console.log('π¦ Raptur is hunting on port 3000');
});
import { Raptur } from 'raptur';
const app = new Raptur();
app.get(path: string, handler: RouteHandler);
app.post(path: string, handler: RouteHandler);
app.put(path: string, handler: RouteHandler);
app.delete(path: string, handler: RouteHandler);
interface RapturRequest {
params: Record<string, string>; // URL parameters
query: Record<string, string>; // Query string parameters
headers: http.IncomingHttpHeaders; // Request headers
json(): Promise<any>; // Parse JSON body
}
interface RapturResponse {
status(code: number): RapturResponse;
json(data: any): void;
send(data: string): void;
setHeader(name: string, value: string): RapturResponse;
}
Raptur supports dynamic URL parameters with the :param
syntax:
app.get('/api/users/:id/posts/:postId', (req, res) => {
const { id, postId } = req.params;
res.json({ userId: id, postId });
});
Access query parameters through the query
object:
// GET /api/search?q=raptor&sort=desc
app.get('/api/search', (req, res) => {
const { q, sort } = req.query;
res.json({ searchTerm: q, sortOrder: sort });
});
Parse JSON request bodies with the json()
method:
app.post('/api/data', async (req, res) => {
const body = await req.json();
res.json({ received: body });
});
Raptur automatically handles route errors:
app.get('/api/error', async (req, res) => {
throw new Error('Something went wrong');
// Automatically returns 500 Internal Server Error
});
app
.get('/api/items', async (req, res) => {
const items = await getItems();
res.json(items);
})
.post('/api/items', async (req, res) => {
const body = await req.json();
const newItem = await createItem(body);
res.status(201).json(newItem);
})
.get('/api/items/:id', async (req, res) => {
const item = await getItem(req.params.id);
if (!item) {
return res.status(404).json({ error: 'Item not found' });
}
res.json(item);
})
.delete('/api/items/:id', async (req, res) => {
await deleteItem(req.params.id);
res.status(204).send('');
});
We welcome contributions! Please feel free to submit a Pull Request. Check out our contributing guidelines for more information.
MIT Β© [Nana Adjei Manu]
ASCII art logo generated with love and prehistoric power! π¦
Happy routing with Raptur! π¦