3.0.5 • Published 3 years ago

claudia-local-api v3.0.5

Weekly downloads
95
License
MIT
Repository
github
Last release
3 years ago

claudia-local-api

CircleCI codecov Codacy Badge npm npm David David license

codecov

Command line utility to launch Express local API for claudia-api-builder. Test drive your lambda functions before deployment

npm install --save-dev claudia-local-api

To install globally:

npm install --global claudia-local-api

Usage

If you have a claudia and claudia-api-builder app/server named lib/app.js ready for deployment and you want to test it locally:

'use strict';

const ApiBuilder = require('claudia-api-builder');

function handleGetRequest(app, req) {
    const body = {
        status: 'OK',
        body: req.body,
        pathParams: req.pathParams,
        query: req.queryString
    };
    return new app.ApiResponse(body, {
        called: 'handleGetRequest'
    }, 200);
}

function handlePostRequest(app, req) {
    const body = {
        status: 'OK',
        body: req.body,
        pathParams: req.pathParams,
        query: req.queryString
    };
    return new app.ApiResponse(body, {
        called: 'handlePostRequest'
    }, 201);
}

function bootstrap() {
    const app = new ApiBuilder();

    app.get('/', handleGetRequest.bind(null, app));
    app.post('/', handlePostRequest.bind(null, app));

    app.get('/users/{id}', handleGetRequest.bind(null, app));
    app.get('/items/{itemId}/{partId}', handleGetRequest.bind(null, app));

    app.post('/objects', handlePostRequest.bind(null, app));

    return app;
}

module.exports = bootstrap()

You can install claudia-local-api and run the command line Express API to test out the lambda function locally:

claudia-local-api --api-module lib/app.js

Or add into your package.json:

"server": "claudia-local-api --api-module lib/app.js"

This will start up a local Express server on port 3000 to proxy requests to your claudia-api-builder app.

You can also pipe it into bunyan to pretty print the log:

claudia-local-api --api-module lib/app.js | bunyan --output short

For full list of options:

claudia-local-api --help
3.0.5

3 years ago

3.0.4

4 years ago

3.0.3

4 years ago

3.0.2

4 years ago

3.0.1

4 years ago

2.0.0

6 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago