# typescript-rest

> A Library to create RESTFul APIs with Typescript

Latest version **3.0.4** (published 2021-06-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install typescript-rest
pnpm add typescript-rest
yarn add typescript-rest
bun add typescript-rest
```

## Health

**Score 35/100 (D)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 3.0.4 |
| Published | 2021-06-10 |
| First published | 2016-09-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=6.0.0 |
| Dependencies | 18 |
| Unpacked size | 1004.1 KB |
| Known vulnerabilities | 0 (+12 in 2 direct dependencies) |
| Install scripts | no |
| GitHub stars | 522 |
| Author | Thiago da Rosa de Bustamante |
| Maintainers | trbustamante |
| Keywords | API, REST, RESTFul, service, microservice, typescript, node server |

## Links

- npm: https://www.npmjs.com/package/typescript-rest
- Repository: https://github.com/thiagobustamante/typescript-rest
- Homepage: https://github.com/thiagobustamante/typescript-rest#readme
- Issues: https://github.com/thiagobustamante/typescript-rest/issues
- npm.io page: https://npm.io/package/typescript-rest

## Dependencies (18)

- [path](https://npm.io/package/path.md) ^0.12.7
- [lodash](https://npm.io/package/lodash.md) ^4.17.21
- [multer](https://npm.io/package/multer.md) ^1.4.2
- [yamljs](https://npm.io/package/yamljs.md) ^0.3.0
- [express](https://npm.io/package/express.md) ^4.17.1
- [fs-extra](https://npm.io/package/fs-extra.md) ^10.0.0
- [passport](https://npm.io/package/passport.md) ^0.4.1
- [body-parser](https://npm.io/package/body-parser.md) ^1.19.0
- [require-glob](https://npm.io/package/require-glob.md) ^4.0.0
- [@types/multer](https://npm.io/package/@types/multer.md) 1.4.5
- [cookie-parser](https://npm.io/package/cookie-parser.md) ^1.4.5
- [@types/express](https://npm.io/package/@types/express.md) ^4.17.12
- [@types/passport](https://npm.io/package/@types/passport.md) ^1.0.6
- [reflect-metadata](https://npm.io/package/reflect-metadata.md) ^0.1.13
- [@types/body-parser](https://npm.io/package/@types/body-parser.md) 1.19.0
- [swagger-ui-express](https://npm.io/package/swagger-ui-express.md) ^4.1.6
- [@types/serve-static](https://npm.io/package/@types/serve-static.md) ^1.13.9
- [@types/cookie-parser](https://npm.io/package/@types/cookie-parser.md) ^1.4.2

## Alternatives

- [launchdarkly-js-client-sdk](https://npm.io/package/launchdarkly-js-client-sdk.md) — 2.5M weekly downloads
- [@elastic/elasticsearch](https://npm.io/package/@elastic/elasticsearch.md) — 2.1M weekly downloads
- [@c8y/client](https://npm.io/package/@c8y/client.md) — 15.3K weekly downloads
- [@signaldb/maverickjs](https://npm.io/package/@signaldb/maverickjs.md) — 1.7K weekly downloads
- [@bbc/http-transport-cache](https://npm.io/package/@bbc/http-transport-cache.md) — 1.2K weekly downloads

## Recent versions

- 3.0.4 (latest) — 2021-06-10
- 3.0.3 — 2021-06-10
- 3.0.2 — 2020-08-17
- 3.0.1 — 2020-02-28
- 3.0.0 — 2020-02-27
- 2.2.6 — 2020-02-11
- 2.2.5 — 2020-02-11
- 2.2.4 — 2020-02-03
- 2.2.2 — 2019-07-20
- 2.2.1 — 2019-07-19
- 2.2.0 — 2019-06-10
- 2.1.0 — 2019-06-07
- 2.0.1 — 2019-05-30
- 2.0.0 — 2019-03-02
- 1.8.1 — 2018-12-27
- … 50 more at https://npm.io/package/typescript-rest/versions

## README

[![npm version](https://badge.fury.io/js/typescript-rest.svg)](https://badge.fury.io/js/typescript-rest)
![Master Workflow](https://github.com/thiagobustamante/typescript-rest/workflows/Master%20Workflow/badge.svg)
[![Coverage Status](https://codecov.io/gh/thiagobustamante/typescript-rest/branch/master/graph/badge.svg)](https://codecov.io/gh/thiagobustamante/typescript-rest)
[![Known Vulnerabilities](https://snyk.io/test/github/thiagobustamante/typescript-rest/badge.svg?targetFile=package.json)](https://snyk.io/test/github/thiagobustamante/typescript-rest?targetFile=package.json)
[![BCH compliance](https://bettercodehub.com/edge/badge/thiagobustamante/typescript-rest?branch=master)](https://bettercodehub.com/)

# REST Services for Typescript
This is a lightweight annotation-based [expressjs](http://expressjs.com/) extension for typescript.

It can be used to define your APIs using decorators.

**Table of Contents** 

- [REST Services for Typescript](#)
  - [Installation](#installation)
  - [Configuration](#configuration)
  - [Basic Usage](#basic-usage)
  - [Using with an IoC Container](#using-with-an-ioc-container)
  - [Documentation](https://github.com/thiagobustamante/typescript-rest/wiki)
  - [Boilerplate Project](#boilerplate-project)  

## Installation

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

```bash
npm install typescript -g
```

To install typescript-rest:

```bash
npm install typescript-rest --save
```

## Configuration

Typescript-rest requires the following TypeScript compilation options in your tsconfig.json file:

```typescript
{
  "compilerOptions": {
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "target": "es6" // or anything newer like esnext
  }
}
```

## Basic Usage

```typescript
import * as express from "express";
import {Server, Path, GET, PathParam} from "typescript-rest";

@Path("/hello")
class HelloService {
  @Path(":name")
  @GET
  sayHello( @PathParam('name') name: string ): string {
    return "Hello " + name;
  }
}

let app: express.Application = express();
Server.buildServices(app);

app.listen(3000, function() {
  console.log('Rest Server listening on port 3000!');
});

```

That's it. You can just call now:

```
GET http://localhost:3000/hello/joe
```

## Using with an IoC Container

Install the IoC container and the serviceFactory for the IoC Container

```bash
npm install typescript-rest --save
npm install typescript-ioc --save
npm install typescript-rest-ioc --save
```

Then add a rest.config file in the root of your project:

```json
{
  "serviceFactory": "typescript-rest-ioc"
}
```

And you can use Injections, Request scopes and all the features of the IoC Container. It is possible to use it with any other IoC Container, like Inversify.

Example:

```typescript
class HelloService {
  sayHello(name: string) {
    return "Hello " + name;
  }
}

@Path("/hello")
class HelloRestService {
  @Inject
  private helloService: HelloService;

  @Path(":name")
  @GET
  sayHello( @PathParam('name') name: string): string {
    return this.sayHello(name);
  }
}
```

## Complete Guide

Check our [documentation](https://github.com/thiagobustamante/typescript-rest/wiki).

## Boilerplate Project

You can check [this project](https://github.com/vrudikov/typescript-rest-boilerplate) to get started.

---
_Source: https://npm.io/package/typescript-rest · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
