Skip to content

A boilerplate project of JSON-RPC version 2 server-side implementation for Express

License

Notifications You must be signed in to change notification settings

yak0/jsonrpc-boilerplate

Repository files navigation

JSON-RPC Express Boilerplate

Build Status

This is a boilerplate project of JSON-RPC version 2 server-side implementation for Express library on NodeJS with Typescript and MongoDB.

Installation

Before install to your local environment, ensure you have installed nodejs and npm

npm install && npm build && npm start

You can also start on docker environment. Before that, ensure you have installed docker and docker-compose. In project root run:

docker-compose up

Test

npm test

Methods

There are 4 request methods as an example. If you are going to create another one, you should implement your class with MethodInterface and you should define your method in config.ts

createEntry

(CreateEntryMethod - CreateEntryParams)

curl -X POST \
  http://localhost:3000/rpc \
  -H 'Content-Type: application/json' \
  -d '{
    "jsonrpc": "2.0",
    "method": "createEntry",
    "params": {
        "title": "my title",
        "content": "my content"
    },
    "id": 1
 }'

updateEntry

(UpdateEntryMethod - UpdateEntryParams)

curl -X POST \
  http://localhost:3000/rpc \
  -H 'Content-Type: application/json' \
  -d '{
    "jsonrpc": "2.0",
    "method": "updateEntry",
    "params": {
        "id": "1fd41202-1759-11ea-a698-6fe04a720c0f",
        "title": "updated title"
    },
    "id": 1
 }'

deleteEntry

(DeleteEntryMethod - DeleteEntryParams)

curl -X POST \
  http://localhost:3000/rpc \
  -H 'Content-Type: application/json' \
  -d '{
    "jsonrpc": "2.0",
    "method": "deleteEntry",
    "params": {
        "id": "1fd41202-1759-11ea-a698-6fe04a720c0f"
    },
    "id": 1
 }'

getEntry

(GetEntryMethod - GetEntryParams)

curl -X POST \
  http://localhost:3000/rpc \
  -H 'Content-Type: application/json' \
  -d '{
    "jsonrpc": "2.0",
    "method": "getEntry",
    "params": {
        "id": "1fd41202-1759-11ea-a698-6fe04a720c0f"
    },
    "id": 1
 }'

getEntries

(GetEntriesMethod - GetEntriesParams)

curl -X POST \
  http://localhost:3000/rpc \
  -H 'Content-Type: application/json' \
  -d '{
    "jsonrpc": "2.0",
    "method": "getEntries",
    "params": {
        "take": 10,
        "skip": 0
    },
    "id": 1
 }'

License

MIT

About

A boilerplate project of JSON-RPC version 2 server-side implementation for Express

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published