I’m crazy green to WSGI on Google App Engine (GAE).
How do I set the content type to JSON? This is what I have so far:
class Instructions(webapp.RequestHandler):
def get(self):
response = {}
response["message"] = "This is an instruction object"
self.response.out.write(json.dumps(response))
application = webapp.WSGIApplication([('/instructions', Instructions)],
debug=True)
def main():
run_wsgi_app(application)
if __name__ == "__main__":
main()
Additionally, I’m building a few RESTful services, nothing too complicated. I was using restlets when I was developing in JAVA. Is there a better framework to be using than WSGI? The only reason I’m using WSGI is because that was what they used in the App Engine tutorial.
Thanks!
You can set the proper Content-Type with something like this:
WSGI is not a framework but a specification; the framework you are currently using is the webapp framework.
There’s nothing sophisticated and specific like Restlet on the Python side; however with webapp you can create RESTful request handlers through regular expressions returning JSON/XML data like your handler does.