From b976126ec72b784d61ff70c3741badad841f1ce7 Mon Sep 17 00:00:00 2001 From: Thiago Bustamante Date: Thu, 27 Feb 2020 23:54:57 -0300 Subject: [PATCH] readme file --- README.md | 48 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0f66386..6a12d89 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ # 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 ES7 decorators. +It can be used to define your APIs using decorators. **Table of Contents** @@ -15,6 +15,7 @@ It can be used to define your APIs using ES7 decorators. - [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) @@ -40,7 +41,8 @@ Typescript-rest requires the following TypeScript compilation options in your ts { "compilerOptions": { "experimentalDecorators": true, - "emitDecoratorMetadata": true + "emitDecoratorMetadata": true, + "target": "es6" // or anything newer like esnext } } ``` @@ -75,6 +77,48 @@ 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).