如何使用Google App Engine和RESTful创建Python?我尝试过使用云端点,但是文档并没有关注RESTful应用编程接口。GAE有没有类似于django-tastypie的东西?
发布于 2014-01-30 09:49:24
https://github.com/budowski/rest_gae
我已经为webapp2上的NDB模型创建了一个完整的REST API。包括权限处理和更多内容。
很想听听你的想法:
class MyModel(ndb.Model):
property1 = ndb.StringProperty()
property2 = ndb.StringProperty()
owner = ndb.KeyPropertyProperty(kind='User')
class RESTMeta:
user_owner_property = 'owner' # When a new instance is created, this property will be set to the logged-in user
include_output_properties = ['property1'] # Only include these properties for output
app = webapp2.WSGIApplication([
# Wraps MyModel with full REST API (GET/POST/PUT/DELETE)
RESTHandler(
'/api/mymodel', # The base URL for this model's endpoints
MyModel, # The model to wrap
permissions={
'GET': PERMISSION_ANYONE,
'POST': PERMISSION_LOGGED_IN_USER,
'PUT': PERMISSION_OWNER_USER,
'DELETE': PERMISSION_ADMIN
},
# Will be called for every PUT, right before the model is saved (also supports callbacks for GET/POST/DELETE)
put_callback=lambda model, data: model
),
# Optional REST API for user management
UserRESTHandler(
'/api/users',
user_model=MyUser, # You can extend it with your own custom user class
user_details_permission=PERMISSION_OWNER_USER,
verify_email_address=True,
verification_email={
'sender': 'John Doe <john@doe.com>',
'subject': 'Verify your email address',
'body_text': 'Click here {{ user.full_name }}: {{ verification_url }}',
'body_html': '<a href="{{ verification_url }}">Click here</a> {{ user.full_name }}'
},
verification_successful_url='/verification_successful',
verification_failed_url='/verification_failed',
reset_password_url='/reset_password',
reset_password_email={
'sender': 'John Doe <john@doe.com>',
'subject': 'Please reset your password',
'body_text': 'Reset here: {{ verification_url }}',
'body_html': '<a href="{{ verification_url }}">Click here</a> to reset'
},
)
], debug=True, config=config)
发布于 2014-01-08 20:28:35
https://github.com/mevinbabuc/Restify
这是我制作的一个轻量级模块,它的作用类似于appengine的ReST接口。您所要做的就是在ReSTify/models.py中定义模型。
您还可以轻松地向其添加身份验证,而无需进行太多调整。
要开始,你所要做的就是
import webapp2
import ReSTify
application = webapp2.WSGIApplication(
[
('/api/.*', ReSTify.ReST),
],
debug=True)
https://stackoverflow.com/questions/19375085
复制相似问题