@hckrnews/express-callback

Express callback

Usage no npm install needed!

<script type="module">
  import hckrnewsExpressCallback from 'https://cdn.skypack.dev/@hckrnews/express-callback';
</script>

README

Express callback

NPM version Downloads Build Status Coveralls Status Scrutinizer Code Quality

import OpenAPIBackend from 'openapi-backend';
import { makeExpressCallback } from '@hckrnews/express-callback'

const specification = {
    info: {
        version: '1.2.3',
    }
}

const logger = {}

const meta = {}

const getPetsController = ({
    context,
    specification,
    logger,
    req,
    res,
    meta,
}) => {
    // do something

    return {
        headers: {
            'Content-Type': 'application/json',
            'Cache-Control': 'no-store, max-age=0',
        },
        statusCode: 200,
        body: {

        },
    }
}

const api = new OpenAPIBackend({ definition: specification });

api.register({
    getPets: makeExpressCallback({
        controller: getPetsController,
        specification,
        logger,
        meta
    })
});

api.init();