Comments (3)
There is code I wrote in Pyramid's master to do this. I can probably strip it out and provide the JsonRpcRenderer
API with an add_adapter
method and a user-specified serializer (defaulting to json.dumps
). I'll have to think about how to allow the user to do it though.
Probably via
renderer = JsonRpcRenderer()
renderer.add_adapter(MyType, lambda v: str(v))
config.add_renderer('myjsonrpc', renderer)
config.add_jsonrpc_endpoint('foo', '/api/jsonrpc', default_renderer='myjsonrpc')
Normally renderers in Pyramid are specified on the view (method), but a default could be provided on the route (endpoint).
from pyramid_rpc.
Yeah, I think configuring it on a per-endpoint basis makes sense. I was trying to figure out how to do that myself, but I don't think I understand the Pyramid architecture well enough to make a patch :/
from pyramid_rpc.
Added this feature in 634223c. You can just add a new renderer to Pyramid and specify it on your endpoint like so
def jsonrpc_renderer(info):
def _render(value, system):
return json.dumps(value)
return _render
config.add_renderer('myjsonrpc', jsonrpc_renderer)
config.add_jsonrpc_endpoint('rpc', '/api/jsonrpc', default_renderer='myjsonrpc')
If you want to use Pyramid 1.4's cool new JSON renderer which supports adapters for custom data types, just do
from pyramid.renderers import JSON
jsonrpc_renderer = JSON()
jsonrpc_renderer.add_adapter(lambda v: v.isoformat(), datetime.datetime)
config.add_renderer('myjsonrpc', jsonrpc_renderer)
config.add_jsonrpc_endpoint('rpc', '/api/jsonrpc', default_renderer='myjsonrpc')
from pyramid_rpc.
Related Issues (20)
- JSON-RPC may be broken on Pyramid 1.1 HOT 1
- Tests don't pass under 2.4 HOT 1
- JSON-RPC methods should be able to be invoked using HTTP GET HOT 4
- DeprecationWarning get always displayed when using python2.6 HOT 3
- AMF support broken? HOT 5
- Issue with named parameters in the request.params HOT 9
- Need to distinguish Forbidden from RequestInvalid in jsonrpc HOT 2
- JsonRpcError: data argument never used HOT 1
- config.scan not found @xmlrpc_method HOT 15
- decide how to handle json-rpc responses
- Encoding error HOT 1
- Support json rpc 2.0 batch HOT 3
- Allow us to disable exception views HOT 2
- JSON-RPC traversal HOT 6
- remove the route predicate and add a pattern for security HOT 5
- MethodPredicate throws AttributeError when tested against batched requests HOT 1
- Cannot handle *args, **kwargs decorators
- MessagePack support HOT 2
- install error HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pyramid_rpc.