Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including magnet-router with all npm packages installed. Try it out:

var magnetRouter = require("magnet-router")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

magnet-router v3.3.0

Readme

Usage

All router api should refer koa-router

Basic

import magnet from 'magnet-core';
import Config from 'magnet-config';
import Logger from 'magnet-bunyan';
import Server from 'magnet-spdy';
import Session from 'magnet-session';
import Router from 'magnet-router';

let app = await magnet([Config, Logger, Server, Session, Router]);

server/controllers/user.js

export default function user({ router }) {
  router

  .get('/users', async function (ctx) {
    ctx.body = [];
  })

  .post('/user', async function (ctx) {
    ctx.body = ctx.request.body;
  })

  .put('/user/:userId', async function (ctx) {
    ctx.body = ctx.params;
  })

  .get('/user/:userId', async function (ctx) {
    ctx.body = ctx.query;
  });
}
RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free