New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@g1suite/api-framework

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@g1suite/api-framework

Minimal Node HTTP router with method-aware dispatch, dynamic params, and a directory loader.

latest
npmnpm
Version
0.1.0
Version published
Maintainers
1
Created
Source

@g1suite/api-framework

Minimal Node HTTP router with method-aware dispatch, dynamic params, and a directory loader.

Router Basics

  • Create a router and register routes:
import { createRouter } from '@g1suite/api-framework';
const router = createRouter();
router.get('/hello', (req, res, ctx) => ctx?.json({ ok: true }));
  • Dynamic params with :param:
router.get('/users/:id', (req, res, ctx) => {
  ctx?.json({ id: ctx?.params.id });
});
  • Middleware:
router.use((req, res, next) => { /* auth, logging, etc */ next(); });

RequestContext

Handlers receive a ctx with:

  • url, method
  • params from dynamic segments
  • query as an object (multi-values grouped)
  • json(data, status?) and text(body, status?)

Loader

Auto-register route modules from a directory:

import { loadRoutesFromDir } from '@g1suite/api-framework';
await loadRoutesFromDir(router, 'src/routes');
  • File src/routes/hello.ts -> GET /hello
  • Nested src/routes/users/list.js -> GET /users/list
  • Bracket params src/routes/users/[id].ts -> /users/:id
  • Named method exports (GET, POST, PUT, PATCH, DELETE, OPTIONS) are registered per method; otherwise a default export is treated as GET.

Method Fallback

  • Static routes: GET fallback when only GET is registered.
  • Dynamic routes: GET fallback is allowed when the exact method is not found.

Server Example

import http from 'node:http';
import { createRouter, loadRoutesFromDir } from '@g1suite/api-framework';
const router = createRouter();
await loadRoutesFromDir(router, 'src/routes');
http.createServer(router.listener()).listen(3000);

FAQs

Package last updated on 10 Nov 2025

Did you know?

Socket

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.

Install

Related posts