Necromancers Playing MTG
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

api-scaffolder

2.2.0 • Public • Published

> Check out the slides < POC, NOT FOR PRODUCTION

api-scaffolder Build Status

A RAML based typescript backend generator.

It will generate a base project structure for your API, since it uses Typescript your API will be typed and your RAML contract will be ensured.

The generated code exposes an express middleware, implement it should be very simple:

import { getMiddleware, registerRouter } from './api';
 
registerRouter(); // initialize all the controllers and register routes
 
app.use(getMiddleware());

Try it

  1. Install the package:
$ npm install -g api-scaffolder
  1. Clone base project (or download it here) and delete api folder.
$ git clone https://github.com/menduz/api-scaffolder-demo . && git checkout tags/base-api  && rm -fr api
  1. Modify the file api.raml
  2. Execute the generator. This will generate the api implementation on api folder.
$ api-scaffolder api.raml -o api
  1. Build & run $ npm install && npm run run

Features

  • Routing: All the controllers automatically register themselves on a router.
  • Method request validation: Internally it uses osprey to perform validations over queryParameters, uriParameters, headers and request.body.
  • Securirity: Provides an easy way (middlewares) to handle security schemas, no more traits for security.
  • Ensures required parameters: If a header or queryParameter is required.
  • Well defined responses: Every response is defined as a class, ex: GetResponse200 | PostResponse403

TODO:

  • Move queryString & headers interfaces to base.ts
  • When json schema is not present, use implicit types from examples.
  • Register globally registered schemas at root level.
  • Emit http-bat base tests. Maybe in the future we can validate the tests against the definition in case some definition would have changed.
  • Middleware decorator
import bodyParser = require("body-parser");
 
class Controller extends ns.AbstractHandler {
    @Api.ApplyMiddlewares([
        bodyParser.urlencoded()
    ])
    post(body: any){
        return new ns.GetResponse200({
            parsedBody: this.currentContext.request.body
        })
    }
}

install

npm i api-scaffolder

Downloadsweekly downloads

2

version

2.2.0

license

none

repository

githubgithub

last publish

collaborators

  • avatar
  • avatar