1.0.0-alpha.11 • Published 5 years ago

afraid v1.0.0-alpha.11

Weekly downloads
16
License
ISC
Repository
github
Last release
5 years ago

NPM Build Status

afraid

😧 Afraid?! You don't need to be: Incoming data of your express route is validated! Type inference included!

npm.io

Installation

npm install afraid --save --no-optional

Usage

import {query, f, fail} from 'afraid';
import * as express from 'express';

const app = express();

app.get('/users', [
    query(
        f('limit').int(),
        f('offset').int(),
        f('filters').string().array().opt(),
    ),
    fail,
], (req, res, next) => {
    // ...
});

Using classes for validation and transformation

Installation

Omitting --no-optional will install required packages class-transformer and reflect-metadata automatically

npm install afraid --save 

Configuration

The following flags in tsconfig.json:

{
  "experimentalDecorators": true,
  "emitDecoratorMetadata": true
}

Usage

import {query, Field, IsInt, fail} from 'afraid'
import * as express from 'express';

const app = express();

class UserDTO {
    @Field name: string;
    @IsInt() @Field age: number;
}

app.post('/users', [
    body(UserDTO),
    fail,
], (req, res, next) => {
    // ...
});

Swagger documentation

Use afraid-swagger to create swagger documentation from afraid middlewares.

1.0.0-alpha.11

5 years ago

1.0.0-alpha.10

5 years ago

1.0.0-alpha.9

5 years ago

1.0.0-alpha.8

5 years ago

1.0.0-alpha.7

5 years ago

1.0.0-alpha.6

5 years ago

1.0.0-alpha.5

6 years ago

1.0.0-alpha.4

6 years ago

1.0.0-alpha.3

6 years ago

1.0.0-alpha.2

6 years ago

1.0.0-alpha.0

6 years ago