1.5.6 • Published 5 years ago

typescript_base_rest_api v1.5.6

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

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
1.5.6

5 years ago

1.5.5

5 years ago

1.5.4

5 years ago

1.5.3

5 years ago

1.5.2

5 years ago

1.5.0

5 years ago

1.3.2

5 years ago

1.3.1

5 years ago

1.3.0

5 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.16

5 years ago

1.1.15

5 years ago

1.1.14

5 years ago

1.1.13

5 years ago

1.1.12

6 years ago

1.1.11

6 years ago

1.1.9

6 years ago

1.1.8

6 years ago

1.1.7

6 years ago

1.1.6

6 years ago

1.1.5

6 years ago

1.1.4

6 years ago

1.1.3

6 years ago

1.1.3-beta

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.2

6 years ago

0.0.37

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago

0.0.36

6 years ago

0.0.35

6 years ago

0.0.34

6 years ago

0.0.33

6 years ago

0.0.32-next-7

6 years ago

0.0.32-next-6

6 years ago

0.0.32-next-5

6 years ago

0.0.32-next-4

6 years ago

0.0.32-next-3

6 years ago

0.0.32-next-2

6 years ago

0.0.32-next-1

6 years ago

0.0.32-next

6 years ago

0.0.32

6 years ago

0.0.31

7 years ago

0.0.30

7 years ago

0.0.29-b

7 years ago

0.0.29

7 years ago

0.0.28

7 years ago

0.0.27

7 years ago

0.0.26

7 years ago

0.0.25

7 years ago

0.0.24

7 years ago

0.0.23

7 years ago

0.0.22

7 years ago

0.0.21

7 years ago

0.0.20

7 years ago

0.0.19

7 years ago

0.0.18

7 years ago

0.0.17

7 years ago

0.0.16

7 years ago

0.0.15

7 years ago

0.0.14

7 years ago

0.0.13

7 years ago

0.0.12

7 years ago

0.0.11

7 years ago

0.0.10

7 years ago

0.0.9

7 years ago

0.0.8

7 years ago

0.0.7

7 years ago

0.0.6

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago