This is a Google tool used to build apps on the same scalable systems that power Google applications and run your web applications on Google’s infrastructure.
Google App Engine (GAP) enables users to build scalable web applications very easily and deploy them on Google’s application infrastructure in the same way that Google is deploying their own apps.
Traditional approach to Web application development:
- Setup Linux / Windows Machine
- Install and configure Webserver
- Install and configure Database
- Write your web application in any programming language
- Deploy app on server and make it available to the entire world
There is an extra overhead to maintain the server and manage databases. Also, if the application becomes popular then it has to handle huge traffic. Again, we need to analyze traffic to focus on popular areas of web application. So the cost of maintaining the application increases. Also, there are chances of hard-disk failure, server crashes, and so on.
All these things will not be required if we use GAP, because on completion, GAP deploys a web application on Google’s scalable infrastructure, so there is no possibility of hard-disk failure, server crash, and so on. Developers can mainly focus on the problem.
Lets see how to create a simple Web app, Soutout, which stores messages that are sent by a user in a database and displays it on a webpage in a sorted order.
Create directory Shoutout
mkdir shoutout
Create app.yaml
This is the main app configuration file.
application: shoutout version: 1 api_version: 1 runtime: pythonhandlers: - url: .* script: main.py
Create file main.py
#!/usr/bin/env pythonimport wsgiref.handlers
from google.appengine.ext import db
from google.appengine.ext import webapp
from google.appengine.ext.webapp import template
class Shout(db.Model):
message = db.StringProperty(required=True)
when = db.DateTimeProperty(auto_now_add=True)
who = db.StringProperty()
class MyHandler(webapp.RequestHandler):
def get(self):
shouts = db.GqlQuery("SELECT * FROM Shout ORDER BY when DESC")
values = {'shouts' : shouts}
self.response.out.write(template.render("main.html", values))
def post(self):
shout = Shout(message=self.request.get("message")
, who=self.request.get("who"))
shout.put()
self.redirect("/")
def main():
app = webapp.WSGIApplication([
(r'.*', MyHandler)
])
wsgiref.handlers.CGIHandler().run(app)
if __name__ == "__main__":
main()
Create file main.html
This is the main page of app.
Run the app using Google App Launcher
<pre> <h1>Shout out</h1>
{% for shout in shouts%}
<div class="container">
<div class="{% ifequal shout.who ""%} row {% else %} row altrow {% endifequal%}">
<div class="text message"> {{ shout.message }} </div>
<div class="text normaltext"> from </div>
{% ifequal shout.who "" %}
<div class="text username"> Anonymous </div>
{% else %}
<div class="text username"> {{shout.who}} </div>
{% endifequal %}
</div>
</div>
{% endfor%}
<form action="" method="post">
<p>Message: <input type="text" name="message"/></p>
<p>From: <input type="text" name="who"/></p>
<p><input type="submit" value="shout"></p>
</form>
You will see the full application running on localhost.
Deploy App on Google’s appspot
Click on Deploy in the Google app launcher to deploy it on Google. Then you can access it @ url: http://shoutout.appspot.com
- Vijayendra Bapte