# karmia-lambda-jsonrpc

> Karmia JSON-RPC 2.0 module for AWS Lambda.

Latest version **0.5.8** (published 2018-04-20) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install karmia-lambda-jsonrpc
pnpm add karmia-lambda-jsonrpc
yarn add karmia-lambda-jsonrpc
bun add karmia-lambda-jsonrpc
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.5.8 |
| Published | 2018-04-20 |
| First published | 2017-12-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=4.0.0 |
| Dependencies | 4 |
| Unpacked size | 35.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | yes |
| GitHub stars | 0 |
| Author | Kazuma Fujimaki |
| Maintainers | fujimaki-k |

## Links

- npm: https://www.npmjs.com/package/karmia-lambda-jsonrpc
- Repository: https://github.com/fujimakishouten/karmia-lambda-jsonrpc
- Issues: https://github.com/fujimakishouten/karmia-lambda-jsonrpc/issues
- npm.io page: https://npm.io/package/karmia-lambda-jsonrpc

## Dependencies (4)

- [typescript](https://npm.io/package/typescript.md) ^2.8.1
- [@types/node](https://npm.io/package/@types/node.md) ^9.6.2
- [@types/mocha](https://npm.io/package/@types/mocha.md) ^5.0.0
- [karmia-converter-jsonrpc](https://npm.io/package/karmia-converter-jsonrpc.md) ^0.3.2

## Recent versions

- 0.5.8 (latest) — 2018-04-20
- 0.5.7 — 2018-04-20
- 0.5.6 — 2018-04-20
- 0.5.5 — 2018-04-20
- 0.5.4 — 2018-04-13
- 0.5.2 — 2018-04-12
- 0.5.1 — 2018-04-12
- 0.5.0 — 2018-04-12
- 0.4.2 — 2018-04-04
- 0.4.0 — 2018-04-03
- 0.3.3 — 2018-04-02
- 0.3.2 — 2018-04-02
- 0.3.1 — 2018-02-23
- 0.3.0 — 2018-02-23
- 0.2.0 — 2018-01-01
- … 2 more at https://npm.io/package/karmia-lambda-jsonrpc/versions

## README

# karmia-jsonrpc

Karmia JSON-RPC 2.0 module for AWS Lambda.

## Installation

```Shell
npm install karmia-lambda-jsonrpc
```

## Example

Also see example directory.

### API Gateway / Lambda
#### Request mapping template
```
#set($parameters = $input.params())
{
    "stage": "$context.stage",
    "user_id": "$context.identity.cognitoIentityId",
    "headers": {
        #foreach($name in $parameters.heaer)
            "$name": "$util.escapeJavaScript($parameters.header.get($name))"
            #if($foreach.hasNext),#end
        #end
    },
    "body": {
        "jsonrpc": "2.0",
        "method": $input.json('$.method'),
        "params": $input.json('$.params'),
        "id": "$context.requestId"
    }
}
```

#### Response mapping template
```
$input.json('$.body');
```

#### Example lambda function
```javascript
// Import modules
const karmia_jsonrpc = require('karmia-lambda-jsonrpc'),
    jsonrpc = new karmia_jsonrpc();

// Add methods
jsonrpc.methods.set('method', (event, context, params) => {
    return Promise.resolve({success: true});
});

/*
// Add multiple method
jsonrpc.methods.set({
    method1: (event, context, parameters) => {},
    method2: (event, context, parameters) => {}
});
*/

// Export handler
exports.handler = async (event) => {
    try {
        return jsonrpc.call(event);
        // You can specify request body instead of to use event.body
        // return jsonrpc.call(event, context, specified_body);
    } catch (error) {
        return Promise.reject({
            jsonrpc: '2.0',
                error: {
                    code: -32603,
                    message: "Internal error",
                    data: error
                },
                id: event.body.id
        });
    }
};
```

---
_Source: https://npm.io/package/karmia-lambda-jsonrpc · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
