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

api-scaffolder

Package Overview
Dependencies
Maintainers
2
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

api-scaffolder

Generate a Typescript API backend from RAML definitions

  • 3.0.8
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
4
increased by33.33%
Maintainers
2
Weekly downloads
 
Created
Source

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:

# create a folder
mkdir my-service
cd my-service

# init git and npm
git init
npm init --yes

# (create an api.raml file)

# scaffold api.raml
api-scaffolder api.raml -o src/myApi

# create and open index.ts
touch index.ts && vim index.ts
import * as express from 'express';

import { setup } from './src/myApi';

export const app = express();

const { middleware, controller } = setup();

app.use('/', middleware);

app.listen(9919, () => {
  console.log('Listening in port 9919');
});

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.
  • 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
        })
    }
}

Keywords

FAQs

Package last updated on 10 Sep 2019

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