首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Google App Engine + Python中的REST API?

Google App Engine + Python中的REST API?
EN

Stack Overflow用户
提问于 2013-10-15 15:01:41
回答 2查看 18.7K关注 0票数 20

如何使用Google App Engine和RESTful创建Python?我尝试过使用云端点,但是文档并没有关注RESTful应用编程接口。GAE有没有类似于django-tastypie的东西?

EN

回答 2

Stack Overflow用户

发布于 2014-01-30 09:49:24

https://github.com/budowski/rest_gae

我已经为webapp2上的NDB模型创建了一个完整的REST API。包括权限处理和更多内容。

很想听听你的想法:

代码语言:javascript
复制
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)
票数 9
EN

Stack Overflow用户

发布于 2014-01-08 20:28:35

https://github.com/mevinbabuc/Restify

这是我制作的一个轻量级模块,它的作用类似于appengine的ReST接口。您所要做的就是在ReSTify/models.py中定义模型。

您还可以轻松地向其添加身份验证,而无需进行太多调整。

要开始,你所要做的就是

代码语言:javascript
复制
import webapp2

import ReSTify

application = webapp2.WSGIApplication(
    [
        ('/api/.*', ReSTify.ReST),
        ],
    debug=True)
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19375085

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档