10.8.1 • Published 2 months ago

@openaddresses/batch-schema v10.8.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

Installation

npm i @openaddresses/batch-schema

Example Usage

import express from 'express';
import Schema from '@openaddresses/batch-schema';
import { Type } from '@sinclair/typebox';

const app = express();
const schema = new Schema(express.Router(), {
    logging: true,  // Enable Morgan Logging
    limit: 50       // Body size for parsing JSON
});

app.use('/api', schema.router);

server();

async function server() {
    await schema.post('/api/:param1/:param2', {
        query: Type.Object({
            example: Type.Optional(Type.Uppercase(Type.String()))
        }),
        params: Type.Object({
            param1: Type.String(),
            param2: Type.Number(),
        }),
        body: Type.Object({
            username: Type.String(),
            password: Type.String(),
        }),
        res: Type.Object({
            token: Type.String()
        }),
    }, (req, res) => {
        return res.json({
            token: 'I only return if the request meets the query & body schemas'
        });
    });
}

API

const schema = new Schema(<router>, <opts>);
Config OptionNotes
routerInstantiated Express router to bind to
optsOptional Opts Object
opts.schemasDirectory of named schemas

schema.api

await schema.api()

Adds a route called GET /schema which allows the caller to get a list of endpoints that the router manages as well as full schema details for every route. If your API is public we recommend enabling this feature, however if you do not wish for API routes to be published, this feature is disabled unless called.

Adds a route called GET /openapi which returns an OpenAPI / Swagger JSON Object

schema.not_found

Adds a middlware which will catch all routes that have not been defined and return a standard error object.

schema.not_found()

schema.error

Adds a middlware which will convert validation errors into a standard JSON error format. This method should be called after all routes are defined. If this method is not called, you must provide your own middleware for converting JSON Schema Validation Errors into express compatible responses.

schema.error()

schema.load

Loads and runs all routes files in a directory

schema.load(directory, config, opts)
Config OptionNotes
directoryDirectory to load .js files from
configConfig option to pass to each route
optsOptional Opts Object
opts.silentSquelch output
10.8.0

2 months ago

10.8.1

2 months ago

10.7.1

2 months ago

10.7.0

2 months ago

10.6.0

3 months ago

10.4.0

3 months ago

10.5.0

3 months ago

10.0.0

3 months ago

10.1.0

3 months ago

10.0.1

3 months ago

10.2.0

3 months ago

10.0.2

3 months ago

10.3.0

3 months ago

9.4.0

3 months ago

9.3.0

4 months ago

9.2.0

5 months ago

9.1.0

6 months ago

8.1.0

1 year ago

8.1.1

1 year ago

9.0.0

1 year ago

8.0.0

1 year ago

7.6.1

1 year ago

7.6.0

1 year ago

7.4.0

1 year ago

7.5.0

1 year ago

7.3.0

2 years ago

5.1.0

2 years ago

5.0.0

2 years ago

6.0.0

2 years ago

7.0.0

2 years ago

7.2.0

2 years ago

7.1.0

2 years ago

4.4.0

2 years ago

4.3.0

2 years ago

4.2.0

2 years ago

3.1.3

2 years ago

4.1.0

2 years ago

4.0.0

2 years ago

3.1.2

2 years ago

3.1.1

2 years ago

3.1.0

2 years ago

3.0.0

2 years ago

2.4.0

2 years ago

2.3.4

2 years ago

2.3.0

2 years ago

2.2.0

2 years ago

2.3.2

2 years ago

2.3.1

2 years ago

2.3.3

2 years ago

2.1.0

2 years ago

2.0.0

2 years ago

1.0.1

3 years ago

1.0.0

3 years ago