Instant API
Like instant soup but API. JSON-RPC2 flavor with Websockets and HTTP.
💾 Install
npm i -s instant-api
📡 Expose task 'makeSoup' at port 3000
var tasks = 'makeSoup': tasks port: processenvPORT || 3000
🤖 tasks/make-soup.js
module { // use parameters console // return result rpc // return param error //rpc.sendParamsError('Missing parameter ...') // return custom error //rpc.sendError('Splash') // use in promise chains // rawQuery(query).then(rpc.sendResult).catch(rpc.sendError) }
📣 Call task...
var message = method: 'makeSoup' params: size: 'medium' jsonrpc: '2.0' id: Math // ... from a browser using HTTP // ... from a browser using Websocketsvar ws = 'ws://localhost:3000'ws { ws}ws { console} // ... from another server// npm install --save request
By default, CORS is enabled but does not permit transmitting credentials. You can specify allowed CORS domains which will also be able to send credentials:
var tasks = 'makeSoup': tasks port: processenvPORT || 3000 corsAllowedDomains: 'example.org' 'test.example.org'
npm run example