
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
instant-api
Advanced tools
Like instant soup but API. JSON-RPC2 flavor with Websockets and HTTP.
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': require('./tasks/make-soup')
}
require('instant-api')(tasks ,{ port: process.env.PORT || 3000 })
🤖 tasks/make-soup.js
module.exports = function (rpc) {
// use parameters
console.log(rpc.params)
// return result
rpc.sendResult('Done. Enjoy!')
// 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.round(Math.random()*1e20)
}
// ... from a browser using HTTP
fetch('http://localhost:3000', {
method: 'POST', body: JSON.stringify( message )
}).then(function(response){
return response.json()
}).then(function(body){
console.log(body.result)
}).catch(console.error)
// ... from a browser using Websockets
var ws = new WebSocket('ws://localhost:3000')
ws.onopen = function () {
ws.send( JSON.stringify(message) )
}
ws.onmessage = function (event) {
console.log(JSON.parse(event.data))
}
// ... from another server
// npm install --save request
require('request').post({
url: 'http://localhost:3000',
json: message
}, function (error, response, body) {
if (!error && response.statusCode === 200) {
console.log(body.result)
} else {
console.error(error || body)
}
})
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': require('./tasks/make-soup')
}
require('instant-api')(tasks ,{
port: process.env.PORT || 3000,
corsAllowedDomains: [ 'example.org', 'test.example.org' ]
})
npm run example
FAQs
Like instant soup but API. JSON-RPC2 flavor with Websockets and HTTP.
The npm package instant-api receives a total of 0 weekly downloads. As such, instant-api popularity was classified as not popular.
We found that instant-api demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 5 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.