
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
@jaris/router
Advanced tools
jaris is still in very early alpha, production usage is not recommended
Router for @jaris/core
$ npm install -S @jaris/core @jaris/router
import server, { text } from '@jaris/core';
import router, { get } from '@jaris/router';
server([router([get('/', conn => text('Hello, world!', conn))])]);
// user.controller.ts
import { json } from '@jaris/core';
const userController = {
// method can be async!
index: async conn => {
// fetch users, etc
return json({ users: [] }, conn);
},
};
export default userController;
// api.routes.ts
import { get } from '@jaris/router';
import userController from './user.controller';
const apiRoutes = [get('/users', userController.index)];
export default apiRoutes;
// index.ts
import server from '@jaris/core';
import router from '@jaris/router';
import apiRoutes from './api.routes.ts';
server([
(conn) => {
console.log('Since the router is also just a middleware itself, we can have as many middleware before or after that we want!');
return conn;
}
router(apiRoutes)
])
Route parameters are defined using a colon in the route definition and are set as object values on conn.params
.
import server, { text } from '@jaris/core';
import router, { get } from '@jaris/router';
server([
router([
get('/users/:userId', conn =>
text(`Hello, user ${conn.params.userId}!`, conn),
),
]),
]);
Prefixes & Middleware
import server, { json, status, halt } from '@jaris/core';
import router, { get, post, group } from '@jaris/router';
// Middleware are the same as @jaris/core
// so they need to follow the same rule
// of returning a new connection
const companyMiddleware = conn => {
const token = conn.headers['Authorization'];
// ... parse token
// fetch user it belongs to
// check if user has access to company
// if you want to continue, return the connection
if (userHasAccess) {
return conn;
}
// otherwise we set errors and tell jaris
// to stop by using the "halt" helper
return pipe(
status(403),
json({ error: 'You do not have permission' }),
halt,
)(conn);
};
server([
router([
// groups need to be spread since
// they return an array of routes
...group({ prefix: 'v1' }, () => [
// will evaluate to /v1/users
get('/users', userController.index),
// leading / trailing slashes are optional
post('users', userController.store),
// groups can be nested
...group(
{
prefix: '/companies/:companyId',
middleware: [companyMiddleware],
},
() => [
// /v1/companies/:companyUid
get('/', companyController.show),
],
),
]),
]),
]);
FAQs
> TODO: description
The npm package @jaris/router receives a total of 0 weekly downloads. As such, @jaris/router popularity was classified as not popular.
We found that @jaris/router demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.