Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

claudia-local-api

suddi349MIT3.0.5

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

claudia, lambda, claudia-api-builder, claudia-local, claudia-dev, lambda-local, lambda-dev, local-server, dev-server, local-api, dev-api

readme

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

changelog

Changelog

The format is based on Keep a Changelog and this project adheres to Semantic Versioning.

[3.0.4] - 2020-05-19

Changed

  • Added error.message into logged error
  • Added integration test to confirm application/x-www-form-urlencoded requests work

[3.0.3] - 2020-05-19

Changed

  • Incorporated user mattdelsordo to support binary response and abbreviate logging

[3.0.2] - 2020-05-19

Changed

  • Updated CircleCI and Greenkeeper badges in README.md

[3.0.1] - 2020-05-19

Added

  • Added .codacy.yml for Codacy analysis
  • Added .mocharc.yml

Changed

  • Migrated to using nyc from istanbul
  • Migrated husky pre-push hooks
  • Migrated to CircleCI v2 pipelines
  • Updated devDependencies to latest versions
  • Updated package.json to new Node.js and NPM version compatibility