Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Mastering Google App Engine
Mastering Google App Engine

Mastering Google App Engine: Build robust and highly scalable web applications with Google App Engine

eBook
S$36.99 S$52.99
Paperback
S$66.99
Subscription
Free Trial

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
Table of content icon View table of contents Preview book icon Preview Book

Mastering Google App Engine

Chapter 2. Handling Web Requests

Now that you understand the runtime environment of Google App Engine quite well, how it deals with an incoming web requests, and how they are handed over to your application, it's time to divert our attention to the most important aspect of web application development—handling and responding to web requests. In this chapter, we will have a look at how to handle web requests from an application that is deployed on Google App Engine. We will study the two main modes of web request handling and then focus on how to render templates, serve static files, and finally, how to use web frameworks.

In this chapter, we will cover the following topics:

  • The CGI and WSGI way of request handling
  • Rendering templates
  • Serving static files
  • Working with web frameworks

Request handling

Instead of jumping straight into the alphabet soup of HTTP, CGI (Common Gateway Interface), WSGI (Web Server Gateway Interface), and so on, we will examine the entire problem of request handling from where all it started. The basic design goal of the Web was sharing information in the form of documents. So, all in all, it was a document-sharing system, where each document had a unique URL like a unique path for each file (ignoring links and shortcuts for the sake of discussion) on a file system. Each document could be linked to other documents. This was the simple HTTP Web.

The initial Web was simple and consisted of two pair of programs. One piece of program, which was called the client (nowadays, it is mostly in the form of a modern desktop or a mobile browser), would request a document by opening a socket for a given server and on a specific port using a very specific request format like this as textual data:

Host: www.mit.edu
GET /publications/quantum/computing/future...

Request handling in App Engine

Now that we know about the two modes of request handling in Google App Engine, how they work, and their respective pros and cons, it's time to divert our attention to request handlingfrom another aspect. As we discussed in the previous chapter, app.yaml is a manifest of your application, and it defines what your application really is. One of the major things that it defines is how your application processes URLs. There are three things that app.yaml defines:

  • Which URLs or URL patterns are processed?
  • In what order are the URLs or URL patterns processed?
  • How exactly are the URLs or URL patterns processed?

To define which URLs are processed, you can define absolute URLs that start with the / character. Alternatively, if you want some flexibility, you can use regular expressions. Regular expressions might contain regular expression groups, which can later be used in a handler description to specify the URL patterns. We will see this in an example shortly.

The...

Rendering templates

We have been returning plain strings so far, and that's been handy for a while. However, things get pretty complicated if you have to return more information with a more detailed and structured page to the user. This is where this string approach gets very complicated and hard to manage.

That's where templates come into play. Just to recap, the idea of a template is to have some placeholder within the content, where the actual values will be rendered so that you can pass to them. There are many templating libraries (each have their different syntax as well at times), but one of the most widely used one is the templating language, which is used by Django, the popular web framework. It is quit intuitive and easy to understand. There's another third-party library named jinja2 that adopts the Django template language in the form of a separate library. Google App Engine has both the Django templates and jinja2 available. If you want to use some other templating...

Serving static resources

We are making progress. From strings to templates, but still no cosmetics. Just plain HTML is what we are serving. However, to add some beautification to the pages, we will have to style it. To style the pages better, we will need style sheets, and style sheets might need images to beautify our pages This means that we have to serve static files as well.

Serving static files is pretty simple. You just need to add a handler in your app.yaml file as usual, but instead of the script node, you need to add a static_dir node, which indicates the directory in which the files that you want to serve are present. Let's modify our earlier app to serve some static files such as style sheets and images:

- handlers:
  - url:/assets/.*
    static_dir: assets

You may have already guessed that any URL that starts with /assets will be handled by this handler. However, instead of invoking a script, it maps itself to a directory called assets, which is located at the root of your...

Using web frameworks

Until now, we have been writing either plain CGI programs, or WSGI handlers that we map in our application manifest file by using regular expressions. This approach of course works, but it is not scalable for even small projects with few pages to be served. This is where we need to grow beyond this and use web frameworks. We have a lot of variety in Python web frameworks, and everyone has their own favorite list of frameworks. App Engine has built-in frameworks that are a part of the App Engine libraries that are available within the runtime environment. However, these might not be the frameworks that you prefer to work with. You might want to use your own favorite web frameworks. Fortunately, that's possible and easy too. We shall review both using built-in frameworks or rolling in your own favorite in the following sections.

Built-in frameworks

There are a couple of web frameworks that come with Google App Engine. The first one is Django, and the second one is...

Request handling


Instead of jumping straight into the alphabet soup of HTTP, CGI (Common Gateway Interface), WSGI (Web Server Gateway Interface), and so on, we will examine the entire problem of request handling from where all it started. The basic design goal of the Web was sharing information in the form of documents. So, all in all, it was a document-sharing system, where each document had a unique URL like a unique path for each file (ignoring links and shortcuts for the sake of discussion) on a file system. Each document could be linked to other documents. This was the simple HTTP Web.

The initial Web was simple and consisted of two pair of programs. One piece of program, which was called the client (nowadays, it is mostly in the form of a modern desktop or a mobile browser), would request a document by opening a socket for a given server and on a specific port using a very specific request format like this as textual data:

Host: www.mit.edu
GET /publications/quantum/computing/future...
Left arrow icon Right arrow icon

Description

Developing web applications that serve millions of users is no easy task, as it involves a number of configurations and administrative tasks for the underlying software and hardware stack. This whole configuration requires not only expertise, but also a fair amount of time as well. Time that could have been spent on actual application functionality. Google App Engine allows you develop highly scalable web applications or backends for mobile applications without worrying about the system administration plumbing or hardware provisioning issues. Just focus writing on your business logic, the meat of the application, and let Google's powerful infrastructure scale it to thousands of requests per second and millions of users without any effort on your part. This book takes you from explaining how scalable applications work to designing and developing robust scalable web applications of your own, utilizing services available on Google App Engine. Starting with a walkthrough of scalability is and how scalable web applications work, this book introduces you to the environment under which your applications exist on Google App Engine. Next, you will learn about Google's datastore, which is a massively scalable distributed NoSQL solution built on top of BigTable. You will examine the BigTable concepts and operations in detail and reveal how it is used to build Google datastore. Armed with this knowledge, you will then advance towards how to best model your data and query that along with transactions. To augment the powerful distributed dataset, you will deep dive into search functionality offered on Google App Engine. With the search and storage sorted out, you will get a look into performing long running tasks in the background using Google App Engine task queues along with sending and receiving emails. You will also examine the memcache to boost web application performance, image processing for common image manipulation tasks. You will then explore uploading, storing, and serving large files using Blobstore and Cloud storage. Finally, you will be presented with the deployment and monitoring of your applications in production along with a detailed look at dividing applications into different working modules.

Who is this book for?

If you have been developing web applications in Python or any other dynamic language but have always wondered how to write highly scalable web applications without getting into system administration and other plumbing, then this is the book for you. No experience in writing scalable applications is required.

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Oct 08, 2015
Length: 368 pages
Edition : 1st
Language : English
ISBN-13 : 9781784396671
Vendor :
Google
Languages :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

Publication date : Oct 08, 2015
Length: 368 pages
Edition : 1st
Language : English
ISBN-13 : 9781784396671
Vendor :
Google
Languages :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just S$6 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just S$6 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total S$ 171.97
Mastering Google App Engine
S$66.99
Python for Google App Engine
S$44.99
Learning Google Apps Script
S$59.99
Total S$ 171.97 Stars icon

Table of Contents

11 Chapters
1. Understanding the Runtime Environment Chevron down icon Chevron up icon
2. Handling Web Requests Chevron down icon Chevron up icon
3. Understanding the Datastore Chevron down icon Chevron up icon
4. Modeling Your Data Chevron down icon Chevron up icon
5. Queries, Indexes, and Transactions Chevron down icon Chevron up icon
6. Integrating Search Chevron down icon Chevron up icon
7. Using Task Queues Chevron down icon Chevron up icon
8. Reaching out, Sending E-mails Chevron down icon Chevron up icon
9. Working with the Google App Engine Services Chevron down icon Chevron up icon
10. Application Deployment Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
(2 Ratings)
5 star 0%
4 star 0%
3 star 100%
2 star 0%
1 star 0%
Rinaldo Jan 02, 2016
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
Be warned fellow programmers! This tome uses Python only. PAKT's promotions department does not mention this serious limitation. Note that Don Sanderson wrote his GAE books twice, once for Java and once for Python, PAKT should do the same!
Amazon Verified review Amazon
Yewande siwoku Jul 04, 2020
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
Didn’t really serve its purpose but it was very neat.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.