如何使用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的Python API問題
- 5. Google App Engine和Google Calendar API
- 6. Google App Engine | Python | APP.YAML
- 7. template.render()Google App Engine(python)
- 8. Google App Engine Python Cron
- 9. Google App Engine通道API問題(Python/Django)
- 10. Google App Engine上的Imaplib Python
- 11. Google App Engine Blob
- 12. onmessage Google App Engine(Java)Channel API
- 13. 從Google App Engine調用Parse.com REST服務
- 14. Google App Engine用戶API
- 15. 替代Google App Engine API?
- 16. Google App Engine遠程API + OAuth
- 17. App Engine和Google Drive API
- 18. App Engine(Python)和配置API
- 19. Google App Engine Python HTML表
- 20. Google App Engine Python,virtualenv和mimetypes
- 21. Google App Engine Python WebApp序列
- 22. Django替換Google App Engine(Python)
- 23. Google-App-Engine-like Datastore for Python
- 24. Google App Engine Python Cron Job
- 25. Google App Engine Python simplejson轉義?
- 26. URL Rewrite - Google App Engine(Python)
- 27. Google App Engine上Rest API的身份驗證
- 28. Google App Engine shell中的Python raw_input
- 29. Python-Google App Engine中的部署錯誤
- 30. Google App Engine中的函數調用 - Python
嘗試採取看看ProtoRPC的服務。端點建立在它們之上,並且它們寫得不錯。 – grim
你可以在GAE上使用Django,這樣可以直接爲你工作。 –
你可以用不同的微型框架構建平靜的api。我個人不使用webapp(2),而是使用bobo來處理這類應用程序。 –