# express-annotator

> Simple typescript annotations for ExpressJS routes

Latest version **0.0.5** (published 2019-08-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install express-annotator
pnpm add express-annotator
yarn add express-annotator
bun add express-annotator
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.5 |
| Published | 2019-08-07 |
| First published | 2018-10-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 9 |
| Unpacked size | 53.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Gabriel Csollei |
| Maintainers | g43riko |
| Keywords | express, expressjs, nodejs, typescript, annotations, spring, decorators, routes |

## Links

- npm: https://www.npmjs.com/package/express-annotator
- Repository: https://github.com/G43riko/Express-annotator
- Homepage: https://github.com/G43riko/Express-annotator#readme
- Issues: https://github.com/G43riko/Express-annotator/issues
- npm.io page: https://npm.io/package/express-annotator

## Dependencies (9)

- [gtools](https://npm.io/package/gtools.md) ^0.1.31
- [rimraf](https://npm.io/package/rimraf.md) ^2.6.2
- [express](https://npm.io/package/express.md) ^4.16.3
- [chai-http](https://npm.io/package/chai-http.md) ^4.2.0
- [typescript](https://npm.io/package/typescript.md) ^3.1.1
- [body-parser](https://npm.io/package/body-parser.md) ^1.18.3
- [cookie-parser](https://npm.io/package/cookie-parser.md) ^1.4.3
- [@types/chai-http](https://npm.io/package/@types/chai-http.md) ^3.0.5
- [@types/cookie-parser](https://npm.io/package/@types/cookie-parser.md) ^1.4.1

## Alternatives

- [@luma.gl/experimental](https://npm.io/package/@luma.gl/experimental.md) — 77.1K weekly downloads
- [persona-harness](https://npm.io/package/persona-harness.md) — 4.7K weekly downloads
- [@tsparticles/effect-bubble](https://npm.io/package/@tsparticles/effect-bubble.md) — 4.6K weekly downloads
- [f3d](https://npm.io/package/f3d.md) — 730 weekly downloads
- [spark-html-motion](https://npm.io/package/spark-html-motion.md) — 298 weekly downloads

## Recent versions

- 0.0.5 (latest) — 2019-08-07
- 0.0.4 — 2018-10-03
- 0.0.3 — 2018-10-03
- 0.0.1 — 2018-10-02

## README

# Express-annotator

## installation
run command `npm install express-annotator`

### javascript

create file `server.js` and write to it:
```javascript
const Routes = require("express-annotator");
const app    = Routes.initApp({port: 3000});

@Routes.Handler()
class Greeting {
    @Routes.Get()
    onGreet(@Params.response() res, 
            @Params.query("name") userSurname = "World") {
        res.send("Hello " + userSurname);
    }
}
Routes.startApp()
```
run command `node server.js`

Visit [localhost:3000](localhost:3000) and you should see text `Hello World`.

Visit [localhost:3000/?name=Pinocchio](localhost:3000/?name=Pinocchio) and you should see text `Hello Pinocchio`.


### Typescript
create file `server.ts` and write to it:
```typescript
import { Routes, Params } from "express-annotator";
import * as express from "express";

const app: express.Application = Routes.initApp({port: 3000});

@Routes.Handler()
class Greeting {
    @Routes.Get()
    public onGreet(@Params.response() res: express.Response, 
                   @Params.query("name") userSurname = "World"): void {
        res.send("Hello " + userSurname);
    }
}
```
run command `tsc server.ts`

run command `node server.js`

Visit [localhost:3000](localhost:3000) and you should see text `Hello World`.

Visit [localhost:3000/?name=Pinocchio](localhost:3000/?name=Pinocchio) and you should see text `Hello Pinocchio`.

## Route methods
### Route
Basic method to create handler for specific route and method
### Get
Annotation create simple *get* handler for route given as parameter
##### parameters
 - path - path to handler relative to parent paths. Default value is **/**
### Post
Annotation create simple *post* handler for route given as parameter
##### parameters
 - path - path to handler relative to parent paths. Default value is **/**
### Put
Annotation create simple *put* handler for route given as parameter
##### parameters
 - path - path to handler relative to parent paths. Default value is **/**
### Delete
Annotation create simple *delete* handler for route given as parameter
##### parameters
 - path - path to handler relative to parent paths. Default value is **/**
 
### SendFile
Method create handler which send content of specific file to client as response
##### parameters
 - fileName - name of file to send 

### Auth
Method turn on/off authentication for specific route. This method can also set authentication method.
##### parameters
 - authentication - set what method could be used for authentication. Default value is `true`
    - `true` - for authentication use global authentication settings
    - `false` - authentication for this method is switched off
    - `(request: express.Request) => boolean` - method that returns true if user has valid access rights otherwise returns false 
    
### Cookie
Method set cookie to client
##### parameters
 - key - cookie name
 - value - cookie value
 - options - advanced options for cookie
     - maxAge - maximal time for cookie 
     - path - path where cookie will be stored

### Redirect
Method redirect each request send to this route to path given as parameter. 
##### parameters
 - destination - url to which the user is redirected
 - onlyRedirect - if `true` then ends after redirect otherwise continue to execute method. Default value is `true`
 
### DownloadFile
Method send file for download to client
##### parameters
 - filePath - path to file on server
 - fileName - default filename used by system visible in download window 
 
 
## Parameter methods
### query
To this parameter will contains value from query parameter. For example `Params.query("name")` will have after visit `localhost:3000/?name=Pinocchio` value *Pinocchio*
###### parameters
 - name - name of the query variable to be associated with the parameter variable
 
### pathVariable
Path variables are stored in url just after the colon. For example `Params.pathVariable("userName")` will have after visit `localhost:3000/userDetail/Pinocchio` (route `/userDetail:userName`) value *Pinocchio*
###### parameters
 - name - name of the variable to be associated with the parameter variable
 
### cookie
To parameter annotated by this method will have value of corresponding cookie.
###### parameters
 - name - name of the cookie to be associated with the variable
 
### header
To parameter annotated by this method will have value of corresponding header.
##### parameters
 - name - name of the header to be associated with the variable

### body
This annotation put in the following parameter request body
##### parameters
 - format - optional parameter use for parsing body. Allowed formats are `JSON`, `XML`, `HTML`, `SVG`

### request
Annotate following parameter as express.Request object

### response
Annotate following parameter as express.Response object

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