🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

typescript_base_rest_api

Package Overview
Dependencies
Maintainers
4
Versions
64
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

typescript_base_rest_api

[![Coverage Status](https://coveralls.io/repos/github/Artear/typescript-base-rest-api-dynamodb-module/badge.svg?branch=master)](https://coveralls.io/github/Artear/typescript-base-rest-api-dynamodb-module?branch=master) [![CircleCI](https://circleci.com/gh

1.5.6
latest
Source
npm
Version published
Weekly downloads
54
86.21%
Maintainers
4
Weekly downloads
 
Created
Source

Typescript base REST API module

Coverage Status CircleCI This is a lightweight annotation-based restify extension for typescript.

Installation:

This library only works with typescript. Ensure it is installed:

npm install typescript -g

To install typescript base rest api:

npm i typescript_base_rest_api

Get started

1. Define a service router

export class ItemRouter extends RouterConfig {
    protected onConfig(): void {
        this.get("/items", ItemService.getItems);
        this.get("/items/:id", ItemService.findById);
    }
}

2. Create a service

export default class ItemService extends BaseService {

    static controller: ItemController = new ItemController();

    @RestifyValidation.isAlphanumeric("id")
    public static findById(req: Request, res: Response, next: Next): void {
        // do stuff
    }
    public static getItems(req: Request, res: Response, next: Next): void {
      // do other stuff
    }

3. Configure your server

let options: ServerOptions = new OptionsBuilder()
    .withName(config.get<string>("server.options.name"))
    .withVersion(config.get<string>("server.options.version"))
    .build();

export let server: Server = new ServerBuilder()
    .withTimeout(config.get<number>("server.options.timeout"))
    .withOptions(options)
    .withQueryParser(queryParser())
    .withRouter(new PingRouter())
    .withRouter(new ItemRouter())
    .withCORS(false)
    .build();

let port = config.get<number>("port");

server.listen(port, function () {
    loggerHelper.info("App online on port: " + port);
});

4. Run your application!

The API will be running at http://localhost:8282

Configure your application

You can configure your application using environment variables. Example:

{
  "port": "PORT",
  "security": {
    "enable": "SECURITY_ENABLE",
    "token": "SECURITY_TOKEN"
  },
  "newrelic": {
    "enable": "NEWRELIC_ENABLE",
    "license_key": "NEWRELIC_LICENSE_KEY",
    "app_name": "NEWRELIC_APP_NAME"
  }
}

Examples

Check examples folder to see some basic usage.

Development

To use lint in development, you need to install typescript and tslist globally:

npm install -g typescript tslint

Keywords

typescript

FAQs

Package last updated on 24 Jun 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