This is a boilerplate project of JSON-RPC version 2 server-side implementation for Express library on NodeJS with Typescript and MongoDB.
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
npm test
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
(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
}'
(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
}'
(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
}'
(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
}'
(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
}'
MIT