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
AU$36.99 AU$53.99
Paperback
AU$67.99
Subscription
Free Trial
Renews at AU$24.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

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 : 9781784394929
Vendor :
Google
Languages :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

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

Packt Subscriptions

See our plans and pricing
Modal Close icon
AU$24.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
AU$249.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 AU$5 each
Feature tick icon Exclusive print discounts
AU$349.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 AU$5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total AU$ 174.97
Mastering Google App Engine
AU$67.99
Python for Google App Engine
AU$45.99
Learning Google Apps Script
AU$60.99
Total AU$ 174.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

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.