Tek*_*uas 19 python rest google-app-engine google-cloud-endpoints
如何使用Google App Engine和Python创建RESTful API?我尝试过使用Cloud Endpoints,但文档并没有关注RESTful API.对于GAE,有类似于django-tastypie的东西吗?
luc*_*mia 12
RESTful api可以基于EndPoint API构建.有一些工具可以帮助您简化事情:
appengine rest服务器(不基于端点)
适用于Google App Engine应用程序的嵌入式服务器,可通过REST API公开您的数据模型,无需额外工作.
https://code.google.com/p/appengine-rest-server/
另一个是基于端点
通过扩展ndb.Model类和端点库提供的功能,此库允许您直接与API方法中的模型实体交互,而不是与ProtoRPC请求交互.例如,而不是:
https://github.com/GoogleCloudPlatform/endpoints-proto-datastore
我为端点编写了一个RESTFul api生成器.
# generate restful api in one line
BigDataLab = EndpointRestBuilder(GPCode).build(
api_name="BigDataLab",
name="bigdatalab",
version="v1",
description="My Little Api"
)
Run Code Online (Sandbox Code Playgroud)
repo:https: //github.com/Tagtoo/endpoints-proto-datastore-rest
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)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
17950 次 |
| 最近记录: |