srpc-framework
v5.0.0
Published
JSON-RPC over HTTP web 'framework'
Downloads
61
Maintainers
Readme
Usage
const { createServer, createInvalidParamsError } = require('srpc-framework')
const { createServer } = require('http') // or https
const functions = { add: ({ a, b }) => a + b }
const paramsValidationFunctions = {
add: (params) => {
if (params instanceof Object !== true) {
return false
}
return typeof params.a === number && typeof params.b === number
}
}
const limit = '1mb'
const port = 8080
const onStartText = `Server successfully launched on port ${port}`
const { listen: startServer } = createServer({ functions, paramsValidationFunctions, limit, createServer })
startServer(port, onStartText)
Overview
JSON-RPC over HTTP web 'framework'
Specification
It adhere to JSON-RPC 2.0
Exceptions:
- No id field - no point in it when over HTTP
- No batch requests - if you need batch requests you wrote your back end poorly and need to refactor it