How-to create a REST service with Google App Engine and Python?

前端 未结 1 371
野的像风
野的像风 2021-02-06 11:09

I want to create a RESTFUL web service that gets a request via the URL that is accessed and then returns the appropriate document for that client. For example, if it was a weat

相关标签:
1条回答
  • 2021-02-06 11:30

    Using the webapp framework, you can capture regular expression groups and pass them to your handler like this:

    class WeatherHandler(webapp.RequestHandler):
      def get(self, location):
        # Do something for location
    
    application = webapp.WSGIApplication([
        ('/temperature/(.*)', WeatherHandler),
    ])
    
    def main():
      run_wsgi_app(application)
    
    if __name__ == "__main__":
      main()
    

    Any parenthesized groups in the regular expression are collected and passed as positional arguments to the get/post/etc methods on your handler.

    0 讨论(0)
提交回复
热议问题