Comments (5)
I believe I have an idea for this.
Have a container with API much like tornado.gen.Task
, as follows:
class Callback(object):
def __init__(self, func, *args, **kwargs):
...
with usage as follows (assuming there exists some function, get_users
, which can query the DB/cache for list of registered users and return them):
@schema.validate(
input_schema={
"type": "object",
"properties": {
"user": {
"enum": [
Callback(get_users)
]
},
},
"required": ["user"]
}
)
def post(self):
...
that would be resolved whenever this post
method is called and the schema would have all Callback
instances replaced with the results of func(*args, **kwargs)
.
Now, introducing this would make schema.validate
immediately slower because it would always recurse through the schema and check for Callback
instances to resolve. To avoid this, I think adding a dynamic=False
kwarg to schema.validate
will be added, and only if dynamic
is True
, will schema.validate
recurse through the schema to resolve it.
So in finality, your snippet would end up looking something like:
@schema.validate(
input_schema={
"type": "object",
"properties": {
"user": {
"enum": [
Callback(get_users)
]
},
},
"required": ["user"]
},
dynamic=True
)
def post(self):
...
Does this sound reasonable?
from tornado-json.
Implementation detail: the actual call will be done through tornado
's yield gen.Task(...)
pattern asynchronously.
from tornado-json.
Ok, sounds nice. Two remarks:
Please think about that I may be want to get different properties from different sources like via AsyncHttpClient oder using Motor (with MongoDB). And maybe I have to prepare the received data in Tornado after fetching them asynchroously.
What about the api documentation? Do you want to run the callback or add just a general hint?
from tornado-json.
Please think about that I may be want to get different properties from different sources like via AsyncHttpClient oder using Motor (with MongoDB). And maybe I have to prepare the received data in Tornado after fetching them asynchroously.
Right, so this would work if the function that did this work was called asynchronously by tornado.gen.Task
, no?
class SchemaCallback(object):
def __init__(self. func, *args, **kwargs):
self.func = func
self.args = args
self.kwargs = kwargs
My idea was just to have SchemaCallback
be a container class and then inside schema.validate
, recurse through the schema and yield gen.Task(func, *args, **kwargs)
any instances of it to resolve the full schema.
What about the api documentation? Do you want to run the callback or add just a general hint?
Maybe this could be the __str__
of the SchemaCallback
?
from tornado-json.
I am new to this so to understand everything here I must see a full example how to use may be AsyncHttpClient().fetch(...)
in the function. Maybe it is really easy. Let's see.
For the documentation __str__
or even better something like get_api_documentation_content()
which refers to an optional init argument and only to __str__
by default would be ok.
from tornado-json.
Related Issues (20)
- Version 1.3.3 apparently only published for Python2 HOT 3
- async handler methods not supported (Tornado 6.x) HOT 2
- Validating query params? HOT 1
- Active project? HOT 1
- Use default values for missing properties. HOT 5
- shouldn't error pages be content-type json? HOT 2
- Error object inconsistency HOT 8
- Possible bug in api_doc_gen HOT 1
- tornado_json.exceptions is missing in the readthedocs documentation
- optional parameters and logging HOT 3
- Integrate apidocjs HOT 1
- @schema.validate allow to transfer custom `IValidator` class that will be used to validate the instance. HOT 1
- pypip.in badges in README are broken
- Generalize schema.validate
- Some problem in APIHander HOT 3
- Python tuples fail to validate as Json lists HOT 1
- Integrate swagger for api documentation
- auto route generation fails when supplied namespaced package HOT 2
- Incomplete response.py present in PyPI source distributions HOT 4
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 tornado-json.