Thank you to remind me of Klein. I'm very new to Twisted and Klein. What I've
known is that Klein is a little like Flask, with which I can implement a
UserAPI as follows:
from flask import Flask
from flask.ext.restful import Api, Resource
api = Flask(__name__)
api = Api(app)
class UserAPI(Resource):
def get(self, user_id):
pass
def post(self, user_id):
pass
api.add_resource(UserAPI, '/users/<int:id>', endpoint='user')
Is there any similar usage in Klein?
在 2015-11-04 12:09:29,"Mashiat Sarker Shakkhar" <[email protected]> 写道:
On 11/3/15 10:15 PM, Wang Yan wrote:
I'm planning to design some REST APIs with Twisted in Python. For example, I
want to use the HTTP method "GET" to fetch a single user's information:
GET http://myhost:8000/api/v1.0/users/[user_id]
I know I should inherit the twisted.web.resource.Resource and implement
"getChild" by myself.
The question is, should I implement a class for each segment of the URI? If so,
I have to implement class API, class V1, class Users and Class User. In other
words, if there're 10 segments in the URI, do I have to implement 10 classes to
represent those resources?
Twisted is too low-level for such use in my opinion. We use Klein
(https://github.com/twisted/klein) which offers nice abstraction above Twisted.
I know this does not answer your question. Just wanted to make sure that you
are aware of possible options.
-Shakkhar
[...]
_______________________________________________
Twisted-Python mailing list
[email protected]
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python