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

koas-core

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

koas-core

> [Koa][] + [OpenAPI Specification][] = Koas

  • 0.7.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2.5K
decreased by-6.11%
Maintainers
1
Weekly downloads
 
Created
Source

Koas-core

Koa + OpenAPI Specification = Koas

Koas aims to make it easy to write a RESTful API based on Koa and an Open API V3 Specification.

This is the core package. For more details, see the mono repository README

Installation

npm install koa koas-core

Usage

const Koa = require('koa');
const { koas } = require('koas-core');

const document = {
  openapi: '3.0.2',
  info: {
    title: 'My API',
    version: '1.0.0',
  },
  paths: {
    '/': {
      get: {
        responses: {},
      },
    },
  },
};

const app = new Koa();
app.use(
  koas(document, [
    // Koas plugins go here.
  ]),
);
app.listen(3333);

Plugins

Plugins are functions that take parameters provided by Koas, and return a Koa middleware. Typically, plugins are returned by a function, so options can be passed in.

Example plugin:

function myPlugin(options) {
  return (document, resolveRef, runAlways, validate) => async (ctx, next) => {
    await next();
  };
}

module.exports = {
  myPlugin,
};

TypeScript typings are provided. So it is also possible to write plugins using TypeScript. Pretty much the only type annotation needed is Plugin as the return option for the function.

import { Plugin } from 'koas-core';

export interface MyPluginOptions {
  myOption: unknown;
}

export function myPlugin(options: MyPluginOptions): Plugin {
  return (document, resolveRef, runAlways, validate) => async (ctx, next) => {
    await next();
  };
}

Keywords

FAQs

Package last updated on 14 Jun 2022

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