如何使用Google App Engine和Python创建RESTful API?我尝试过使用云端点,但文档不关注RESTful API。 GAE有没有类似于django-tastypie的东西?Google App Engine + Python中的REST API?
回答
可以基于EndPoint API构建RESTful API。有一些工具可以帮助你使事情更容易:
AppEngine上休息服务器(不是基于端点)
投入式服务器,它通过REST API没有暴露你的数据模型谷歌App Engine应用程序加班。
https://code.google.com/p/appengine-rest-server/
另一种是基于端点
通过扩展ndb.Model类提供的功能和终端库,这个库可以让你直接在模型实体交互的API方法而不是ProtoRPC请求。例如,而不是:
https://github.com/GoogleCloudPlatform/endpoints-proto-datastore
EDIT1:
我写了端点一个RESTful API生成。
# generate restful api in one line
BigDataLab = EndpointRestBuilder(GPCode).build(
api_name="BigDataLab",
name="bigdatalab",
version="v1",
description="My Little Api"
)
回购: https://github.com/Tagtoo/endpoints-proto-datastore-rest
太棒了!我正在使用Appengine Rest Server。但验证者和授权人必须手动实施。你能指点我一些资源吗? – theG33k
https://github.com/mevinbabuc/Restify
这是我由轻质模块,它的作用就像一个REST接口为应用服务引擎。 您只需在ReSTify/models.py中定义模型即可。
您还可以轻松地添加身份验证,而无需调整太多。
要开始人,你要做的就是
import webapp2
import ReSTify
application = webapp2.WSGIApplication(
[
('/api/.*', ReSTify.ReST),
],
debug=True)
https://github.com/budowski/rest_gae
我已经创建了NDB车型在webapp2的一个全面的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 <[email protected]>',
'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 <[email protected]>',
'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)
这很棒!您选择不利用终端的任何原因? – wprater
@wprater,https://code.google.com/p/googleappengine/issues/detail?id=9384这可能是其中一个原因... – opensourcegeek
@opensourcegeek我结束了使用这个(https:// github .com/GoogleCloudPlatform/endpoints-proto-datastore),因为我想使用端点,但是这个库看起来也很棒! – wprater
- 1. 调用Python API - Google App Engine
- 2. Python - Google App Engine
- 3. App Engine的Python REST框架?
- 4. Google App Engine和Google Calendar API
- 5. template.render()Google App Engine(python)
- 6. Google App Engine Python Cron
- 7. Google App Engine | Python | APP.YAML
- 8. Google App Engine通道API问题(Python/Django)
- 9. Google App Engine搜索API
- 10. Google App Engine上的Imaplib Python
- 11. onmessage Google App Engine(Java)Channel API
- 12. Google App Engine Blob
- 13. Google App Engine用户API
- 14. 替代Google App Engine API?
- 15. Google App Engine远程API + OAuth
- 16. App Engine和Google Drive API
- 17. App Engine(Python)和配置API
- 18. Google-App-Engine-like Datastore for Python
- 19. Google App Engine Python HTML表
- 20. URL Rewrite - Google App Engine(Python)
- 21. Google App Engine Python WebApp序列
- 22. Google App Engine Python,virtualenv和mimetypes
- 23. Django替换Google App Engine(Python)
- 24. Google App Engine Python Cron Job
- 25. Google App Engine Python simplejson转义?
- 26. Google App Engine上Rest API的身份验证
- 27. Google App Engine中的函数调用 - Python
- 28. Google App Engine中的用户代理python
- 29. Google App Engine shell中的Python raw_input
- 30. Google App Engine是否支持JAVA Proxy API?
尝试采取看看ProtoRPC的服务。端点建立在它们之上,并且它们写得不错。 – grim
你可以在GAE上使用Django,这样可以直接为你工作。 –
你可以用不同的微型框架构建平静的api。我个人不使用webapp(2),而是使用bobo来处理这类应用程序。 –