How to use where clause in Knex
Create refunds with Stripe
Load HTML with Cheerio
How to send POST request with Axios
Find intersection of array in Lodash
Powered by Official white Bloop logo with a period

Terms / Privacy / Search / Support

  • app.use(async ctx => {
      ctx; // is the Context
      ctx.request; // is a Koa Request
      ctx.response; // is a Koa Response
    });
    Docs
  • //...
    const logger = require('koa-logger');
    const serve = require('koa-static');
    const route = require('koa-route');
    const koa = require('koa');
    const path = require('path');
    const app = module.exports = koa();
    
    // Logger
    app.use(logger());
    
    app.use(route.get('/', messages.home));
    app.use(route.get('/messages', messages.list));
    app.use(route.get('/messages/:id', messages.fetch));
    app.use(route.post('/messages', messages.create));
    app.use(route.get('/async', messages.delay));
    
    //...
    
    /Azure/phippyandfriends MIT
  • app.use(respond({
      methods: {
        shizzle: (ctx, message) => {
          ctx.send(200, message + ', fo-shizzle');
        }
      }
    }));
     
    app.use((ctx) => {
      // HTTP 200 { message: 'Koa is the best, fo-shizzle' }
    // HTTP 200 { message: 'Koa is the best, fo-shizzle' }
      ctx.shizzle('Koa is the best');
    });
    Docs
  • const koa = require('koa');
    const router = require('koa-joi-router');
    const Joi = router.Joi;
    
    const public = router();
    
    public.get('/', async (ctx) => {
      ctx.body = 'hello joi-router!';
    });
    
    public.route({
      method: 'post',
      path: '/signup',
      validate: {
        body: {
          name: Joi.string().max(100),
          email: Joi.string().lowercase().email(),
          password: Joi.string().max(100),
          _csrf: Joi.string().token()
        },
        type: 'form',
        output: {
          200: {
            body: {
              userId: Joi.string(),
              name: Joi.string()
            }
          }
        }
      },
      handler: async (ctx) => {
        const user = await createUser(ctx.request.body);
        ctx.status = 201;
        ctx.body = user;
      }
    });
    
    const app = new koa();
    app.use(public.middleware());
    app.listen(3000);
    Docs
  • const Koa = require("koa")
    const router = require('koa-joi-router');
    
    const pub = router();
    const admin = router();
    const auth = router();
    
    // add some routes ..
    pub.get('/some/path', async () => {});
    admin.get('/admin', async () => {});
    auth.post('/auth', async () => {});
    
    const app = new Koa();
    app.use(pub.middleware());
    app.use(admin.middleware());
    app.use(auth.middleware());
    app.listen();
    Docs
  • Powered by Official black Bloop logo with a period
    download the IDE extension

    View other examples