0.2.18 • Published 15 days ago

ts-api-decorators-express v0.2.18

Weekly downloads
37
License
Apache-2.0
Repository
github
Last release
15 days ago

Express API Decorators

This library allows you to use Typescript API Decorators with the Express framework.

Installation

This library performs preprocessing on APIs during the typescript compilation step. See Configuring Transformers for how to set this up. If you want to get started faster, check out the simple example in (examples/express/simple)../../examples/express/simple.

Usage (Defining an API)

APIs are defined as methods on a class:

import { Api, ApiGetMethod } from 'ts-api-decorators-express';

@Api
class MyApi {
	@ApiGetMethod('/hello')
	greet() {
		return 'Hello World!';
	}
}

This defines an API that exposes a single GET handler at /hello that returns the string Hello World!. Next, create an instance of ManagedApi to handle requests:

import express from 'express';
import { ManagedApi } from 'ts-api-decorators-express';

// Instantiate ManagedApi
const api = new ManagedApi();
api.addHandlerClass(MyApi);

// Instantiate Express
const app = express();
app.use(api.init());
app.listen(3000);

For complete documentation on functionality, see the README at the root of the repo..

Access Express Functionality

You can access the Express request and response objects using Decorators:

import { Api, ApiGetMethod, ExpressApiRequestParam, ExpressApiResponseParam } from 'ts-api-decorators-express';
import * as express from 'express';

@Api
class MyApi {
	@ApiGetMethod('/hello')
	greet(
		@ExpressApiRequestParam() req: Express.Request,
        @ExpressApiResponseParam() res: Express.Response,
	) {
		// ...
	}
}
0.2.18

15 days ago

0.2.17

2 months ago

0.2.16

3 months ago

0.2.14

3 months ago

0.2.13

5 months ago

0.2.12

5 months ago

0.2.11

5 months ago

0.2.9

5 months ago

0.2.8

5 months ago

0.1.58

7 months ago

0.1.59

7 months ago

0.1.60

7 months ago

0.1.61

7 months ago

0.1.57

1 year ago

0.1.52

1 year ago

0.1.53

1 year ago

0.1.54

1 year ago

0.1.55

1 year ago

0.1.56

1 year ago

0.1.50

1 year ago

0.1.51

1 year ago

0.1.49

1 year ago

0.1.46

2 years ago

0.1.47

2 years ago

0.1.48

2 years ago

0.1.45

2 years ago

0.1.41

2 years ago

0.1.42

2 years ago

0.1.43

2 years ago

0.1.44

2 years ago

0.1.40

2 years ago

0.2.7

2 years ago

0.2.1

2 years ago

0.2.3

2 years ago

0.2.2

2 years ago

0.2.5

2 years ago

0.2.4

2 years ago

0.2.0

3 years ago

0.1.38

4 years ago

0.1.37

4 years ago

0.1.36

4 years ago

0.1.32

4 years ago

0.1.33

4 years ago

0.1.34

4 years ago

0.1.35

4 years ago

0.1.30

4 years ago

0.1.31

4 years ago

0.1.27

4 years ago

0.1.28

4 years ago

0.1.26

4 years ago

0.1.20

4 years ago

0.1.21

4 years ago

0.1.22

4 years ago

0.1.23

4 years ago

0.1.19

4 years ago

0.1.18

4 years ago

0.1.17

4 years ago

0.1.16

4 years ago

0.1.15

4 years ago

0.1.14

4 years ago

0.1.13

4 years ago

0.1.12

4 years ago

0.1.10

4 years ago

0.1.11

4 years ago

0.1.9

4 years ago

0.1.7

4 years ago

0.1.6

4 years ago

0.1.5

4 years ago

0.1.4

4 years ago

0.1.3

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago