brianbelhumeur / node-express-json-rpc2 Goto Github PK
View Code? Open in Web Editor NEWA node.js Express middleware to handle JSON-RPC (v2) requests within routes
License: MIT License
A node.js Express middleware to handle JSON-RPC (v2) requests within routes
License: MIT License
As described here:
http://www.jsonrpc.org/historical/json-rpc-over-http.html#errors
I would love to have responses with HTTP error codes corresponding to the JSON-RPC error codes:
404 - Method not found
400 - Invalid request
500 - any other error
var fs = require('fs'); res.rpc('filecontent', function (params, respond) { fs.readFile('readme.txt', function(err, data) { respond({ result: 'ok:)'}); }); });
response is null
so there's no guarantee anything is going to be in req.body
the line rpcList = req.body should be changed to
rpcList = req.body || req.query;
that way it handles posts and gets
Hope all is going well.
it is
app.use( jsonrpc() );
instead of
app.use( express.jsonrpc() );
Hi there,
I am getting an the following error when starting node -
app.use( express.jsonrpc() );
^
TypeError: Object function createApplication() {
var app = connect();
utils.merge(app, proto);
app.request = { proto: req };
app.response = { proto: res };
app.init();
return app;
} has no method 'jsonrpc'
My setup code is as follows -
var express = require('express')
, routes = require('./routes')
, user = require('./routes/user')
, jobs = require('./routes/jobs')
, http = require('http')
, path = require('path')
, jsonrpc = require('node-express-json-rpc2');
var app = express();
// all environments
app.set('port', process.env.PORT || 3000);
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use( express.jsonrpc() );
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));
Is this a bug or have I messed up?!
Thanks,
Sean
edit:
I added express.jsonrpc = jsonrpc and the error is no more however all rpc calls come back with method not found errors.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.