Skip to content

sombriks/koa-api-builder

Repository files navigation

tests and coverage npm version license

Helper to build koa-router apis easily

Dependencies

  • node 14 or higher
  • koa-router
  • koa

Sample usage

import ApiBuilder from "koa-api-builder";

const group = new ApiBuilder().path((group) => {
  group.post('/login', loginRequest)
    .post('/signup', signupRequest)
    .path('/user/:userId/accounts', ifAuthenticated, (group) => {
      group.get(listAccountsRequest)
        .post(ifAllowed, insertAccountRequest)
        .path('/:accountId', (group) => {
          group.get(findAccountRequest);
          group.put(updateAccountRequest);
          group.del(ifAllowed, delAccountRequest);
          group.get('/transactions', listTransactionsRequest);
        });
    });
});

// then we build our api definition into a regular koa-router
const router = group.build();

Similar libraries

See router section on koa wiki

Inspiration

This api builder is heavily copied from Javalin's group handler

Roadmap

  • Initial implementation
  • Test and coverage
  • Publish npm package
  • Add linting tool
  • Publish every new tag
  • Publish coverage results
  • Add special render pseudo-verb for template engines
  • Add Server Sent Events configuration support
  • Add WebSockets configuration support

See the changelog for more details

About

Helper to build koa-router apis easily

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published