npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

api-scaffolder

v3.0.8

Published

Generate a Typescript API backend from RAML definitions

Downloads

28

Readme

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:

  • [x] Move queryString & headers interfaces to base.ts
  • [x] When json schema is not present, use implicit types from examples.
  • [x] 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
        })
    }
}