
Security News
Package Maintainers Call for Improvements to GitHub’s New npm Security Plan
Maintainers back GitHub’s npm security overhaul but raise concerns about CI/CD workflows, enterprise support, and token management.
simple-api-router
Advanced tools
A lightweight, flexible routing framework for building scalable and maintainable API infrastructures in JavaScript, with simple endpoint management and dynamic routing capabilities
A lightweight, flexible API
routing library for JavaScript
that provides a simple and extensible way to define and manage API Endpoints
.
API
and Endpoint
class structureThis example is taken from a Full Working Example
Defining an API
import { Api, Endpoint } from 'simple-api-router';
const API = new Api("/api/");
API.addEndpoint(new Endpoint("time", "GET", (req, res) => {
return STATE.respondWithContent(res, Date.now().toString(), STATE.TEXT_HTML);
}));
const HTTPS_SERVER = createServerHTTPS(STATE.loadDefaultSecureContext(), (req, res) => {
if (API.checkFindExecute(req, res)) {
return;
}
...
})...
Calling an API
fetch("/api/time").then((response) => response.json().then((time) => console.log(time)));
Api
Classnew Api(apiRoute)
: Create a new API with a base routeaddEndpoint(endpoint)
: Add an endpoint to the APIcheckRoute(url)
: Check if a URL matches the API's base routefindEndpoint(endpointPath)
: Find an endpoint matching a given pathfindEndpointCheckMethod(req)
: Find an endpoint and verify its HTTP methodcheckFindExecute(req, res)
: Attempt to execute the handler for a matching endpointEndpoint
Classnew Endpoint(path, method, handler)
: Create a new endpointcheckMethod(method)
: Verify the HTTP methodexecuteHandler(req, res)
: Execute the endpoint's handlerexecuteHandlerArgs(req, res, ...args)
: Execute the handler with additional argumentsApi
class manages a collection of endpoints for a specific route prefixEndpoint
instances define specific path, HTTP method, and handler combinationscheckFindExecute
method provides a convenient way to route and handle requestsFAQs
A lightweight, flexible routing framework for building scalable and maintainable API infrastructures in JavaScript, with simple endpoint management and dynamic routing capabilities
We found that simple-api-router demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers 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
Maintainers back GitHub’s npm security overhaul but raise concerns about CI/CD workflows, enterprise support, and token management.
Product
Socket Firewall is a free tool that blocks malicious packages at install time, giving developers proactive protection against rising supply chain attacks.
Research
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.