Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

koa-route

Package Overview
Dependencies
Maintainers
8
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

koa-route

Koa route middleware

  • 2.4.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
124K
decreased by-0.11%
Maintainers
8
Weekly downloads
 
Created

What is koa-route?

The koa-route package is a simple routing middleware for Koa, a web framework for Node.js. It allows you to define routes for your Koa application in a clean and straightforward manner.

What are koa-route's main functionalities?

Basic Routing

This feature allows you to define basic routes for your Koa application. In this example, two routes are defined: one for the home page and one for the about page.

const Koa = require('koa');
const route = require('koa-route');
const app = new Koa();

const home = ctx => {
  ctx.body = 'Home Page';
};

const about = ctx => {
  ctx.body = 'About Page';
};

app.use(route.get('/', home));
app.use(route.get('/about', about));

app.listen(3000);

Route Parameters

This feature allows you to define routes with parameters. In this example, a route is defined to handle user IDs, and the ID is extracted from the URL and used in the response.

const Koa = require('koa');
const route = require('koa-route');
const app = new Koa();

const user = (ctx, id) => {
  ctx.body = `User ID: ${id}`;
};

app.use(route.get('/user/:id', user));

app.listen(3000);

HTTP Methods

This feature allows you to define routes for different HTTP methods. In this example, separate routes are defined for GET and POST requests to the /user endpoint.

const Koa = require('koa');
const route = require('koa-route');
const app = new Koa();

const getUser = ctx => {
  ctx.body = 'GET User';
};

const createUser = ctx => {
  ctx.body = 'POST User';
};

app.use(route.get('/user', getUser));
app.use(route.post('/user', createUser));

app.listen(3000);

Other packages similar to koa-route

Keywords

FAQs

Package last updated on 28 Nov 2014

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc