JSPM

koapi

1.0.3
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 277
  • Score
    100M100P100Q47332F
  • License MIT

RESTful API framework based on koajs

Package Exports

  • koapi

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (koapi) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

koapi

RESTful API framework based on koa and bookshelf

Build a RESTful API with Koa will be dead simple

create ./server.js

import Koapi from 'koapi';

var app = new Koapi({
  knex:{
    // knex options
  }
});

// use koa middleware if you need
// app.use(koa middleware)

app.router();

app.run();

create ./app/routers/posts.js

import {Router} from 'koapi';
import Post from '../models/post';

const posts = new Router();
posts.get('/posts', function*(){
  this.body = yield Post.fetchAll();
});
posts.get('/posts/:id', function*(){
  var post = yield Post.where('id', '=', this.params.id).fetch();
  this.body = post;
});
export default posts;

create ./app/models/post.js

import { Model } from 'koapi';

export default Model({
  tableName: 'posts',
});