App Engine Web App Framework Jim Eng

Slides:



Advertisements
Similar presentations
JQuery MessageBoard. Lets use jQuery and AJAX in combination with a database to update and retrieve information without refreshing the page. Here we will.
Advertisements

Error HandlingPHPMay-2007 : [#] PHP Error Handling.
Categories of I/O Devices
Chapter 3: Editing and Debugging SAS Programs. Some useful tips of using Program Editor Add line number: In the Command Box, type num, enter. Save SAS.
Web Basics Willem Visser RW334. Overview Basic Browser and Server Interaction – Forms with actions, url encoding and handlers – Parameters – Having more.
LBSC 690 Session #10 Programming, JavaScript Jimmy Lin The iSchool University of Maryland Wednesday, November 5, 2008 This work is licensed under a Creative.
Computer Programming and Basic Software Engineering 4. Basic Software Engineering 1 Writing a Good Program 4. Basic Software Engineering 3 October 2007.
Python and Web Programming
Form Handling, Validation and Functions. Form Handling Forms are a graphical user interfaces (GUIs) that enables the interaction between users and servers.
Web server and web browser It’s a take and give policy in between client and server through HTTP(Hyper Text Transport Protocol) Server takes a request.
1 Spidering the Web in Python CSC 161: The Art of Programming Prof. Henry Kautz 11/23/2009.
J2EE Web Fundamentals Lesson 1 Introduction and Overview
JavaScript & jQuery the missing manual Chapter 11
Googe App Engine Codelab Marzia Niccolai May 28-29, 2008.
Cloud computing lectures: Programming with Google App Engine Keke Chen.
Functions Part I (Syntax). What is a function? A function is a set of statements which is split off into a separate entity that can be used like a “new.
Invitation to Computer Science, Java Version, Second Edition.
Instructor: Chris Trenkov Hands-on Course Python for Absolute Beginners (Spring 2015) Class #002 (January 17, 2015)
CS378 - Mobile Computing Intents.
PHP Workshop ‹#› PHP Error Handling. PHP Workshop ‹#› Types There are 12 unique error types, which can be grouped into 3 main categories: Informational.
11 Web Services. 22 Objectives You will be able to Say what a web service is. Write and deploy a simple web service. Test a simple web service. Write.
Lecture # 6 Forms, Widgets and Event Handling. Today Questions: From notes/reading/life? Share Personal Web Page (if not too personal) 1.Introduce: How.
JAVA SERVER PAGES. 2 SERVLETS The purpose of a servlet is to create a Web page in response to a client request Servlets are written in Java, with a little.
Data Streams David Meredith Source Chapter 19 of – Shiffman, D. (2008). Learning Processing. Morgan Kaufmann, Burlington, MA. ISBN:
Exploring an Open Source Automation Framework Implementation.
CS378 - Mobile Computing Intents. Allow us to use applications and components that are part of Android System – start activities – start services – deliver.
Agenda Review C++ Library Functions Review User Input Making your own functions Exam #1 Next Week Reading: Chapter 3.
PC204 Lecture 9 Conrad Huang Genentech Hall, N453A x
First Indico Workshop WEB FRAMEWORKS Adrian Mönnich May 2013 CERN.
Python – May 11 Briefing Course overview Introduction to the language Lab.
Google App Engine Using Templates Jim Eng Thanks to Chuck Severance
HTTP - Forms - AppEngine Jim Eng
Intro to PHP IST2101. Review: HTML & Tags 2IST210.
Google App Engine Data Store ae-10-datastore
Python uses boolean variables to evaluate conditions. The boolean values True and False are returned when an expression is compared or evaluated.
CSC 110 Using Python [Reading: chapter 1] CSC 110 B 1.
VENUE FINDER. This application provide up to date information of locations where particular music events are taking place on an specific date. The application.
Google App Engine MemCache ae-09-session
Google Application Engine Introduction Jim Eng with thanks to Charles Severance
ProgLan Python Session 4. Functions are a convenient way to divide your code into useful blocks, allowing us to: order our code, make it more readable,
ITM © Port, Kazman1 ITM 352 More on Forms Processing.
 Registry itself is easy and straightforward in implementation  The objects of registry are actually complicated to store and manage  Objects of Registry.
IS-907 Java EE World Wide Web - Overview. World Wide Web - History Tim Berners-Lee, CERN, 1990 Enable researchers to share information: Remote Access.
GUIs Basic Concepts. GUI GUI : Graphical User Interface Window/Frame : a window on the screen Controls/Widgets : GUI components.
CIS Intro to JAVA Lecture Notes Set July-05 GUI Programming –TextField Action Listeners, JEditorPane action listeners, HTML in a JEditorPane,
Python Let’s get started!.
ASP-2-1 SERVER AND CLIENT SIDE SCRITPING Colorado Technical University IT420 Tim Peterson.
PROGRAMMING IN PYTHON LETS LEARN SOME CODE TOGETHER!
Searching CSE 103 Lecture 20 Wednesday, October 16, 2002 prepared by Doug Hogan.
Function as a Service An Ad Hoc Approach to Cloud Computing By Keith Downie.
Today… Strings: –String Methods Demo. Raising Exceptions. os Module Winter 2016CISC101 - Prof. McLeod1.
Getting Started With Python Brendan Routledge
Lesson 11. CGI CGI is the interface between a Web page or browser and a Web server that is running a certain program/script. The CGI (Common Gateway Interface)
University of Kansas Department of Electrical Engineering and Computer Science Dr. Susan Gauch April 21, 2005 I T T C Introduction to Web Technologies.
Presented by Alexey Vedishchev Developing Web-applications with Grails framework American University of Nigeria, 2016 Part VI: Mapping URLs.
Google App Engine An Example!. Schedule Today: AppEngine and Python Wednesday: Review and CES! Friday Quiz!!! Next week: – DEMO MADNESS!!! – Approx 20.
Development Environment
Data Virtualization Tutorial: Introduction to SQL Script
z/Ware 2.0 Technical Overview
Play Framework: Introduction
Logging In ASP.Net Core 1.1.
Functions CIS 40 – Introduction to Programming in Python
Python Web Development
Logging In ASP.Net Core 2.0.
AJAX Robin Burke ECT 360.
Lesson 12.
Introduction to TouchDevelop
CISC101 Reminders Assignment 3 due next Friday. Winter 2019
Bryan Burlingame 24 April 2019
Presentation transcript:

App Engine Web App Framework Jim Eng

Review: app.yaml application: ae-03-webapp version: 1 runtime: python api_version: 1 handlers: - url: /.* script: index.py The app.yaml file routes requests amongst different Python scripts.

Looking ahead application: ae-03-dual version: 1 runtime: python api_version: 1 handlers: - url: / script: index.py - url: /guess script: guess.py- url: /dumper script: dumper.py The app.yaml file routes requests amongst different Python scripts.

import os -- Library Reference

import sys

The webapp Framework While we could write our application using the low-level data provided to our Python code, this would become very tedious We would constantly be reading a lot of Internet Standards documents

The webapp Framework Someone has already written the common code that knows all the details of HTTP (HyperText Transport Protocol) We just import it and then use it. import wsgiref.handlers from google.appengine.ext import webapp

import wsgiref.handlers

import wsgiref.handlers

from google.appengine.ext import webapp ingstarted/usingwebapp.html

from google.appengine.ext import webapp ingstarted/usingwebapp.html

Starting the Framework Define our application and the routing of input URLs to “Handlers” Starting the framework to process the current request def main(): application = webapp.WSGIApplication([ ('/.*', MainHandler)],debug=True) wsgiref.handlers.CGIHandler().run(application)

What is a Handler? When we are dealing with a framework - at times the framework needs to ask us a question or involve us with some bit of processing. Often this is called “event processing” or “event handling” Another word for this is “callbacks” We register interest in certain actions and then when those actions happen - we get called.

MainHandler() When you see a GET or POST matching a URL pattern, please call my MainHandler() The Framework Register Call Back “Abstraction”

Starting the Framework Sometimes we start the framework - and sometimes it starts us In this example - we are starting the framework and giving it an initial configuration def main(): application = webapp.WSGIApplication([ ('/.*', MainHandler)],debug=True) wsgiref.handlers.CGIHandler().run(application)

main() GET /... webapp( ) MainHandler() our code framework Our main program starts the framework and passes it an initial list of URL routes and the name of the handler code for each route. def main(): application = webapp.WSGIApplication([ ('/.*', MainHandler)],debug=True) wsgiref.handlers.CGIHandler().run(application)

Review: app.yaml application: ae-03-webapp version: 1 runtime: python api_version: 1 handlers: - url: /.* script: index.py def main(): application = webapp.WSGIApplication([ ('/.*', MainHandler)],debug=True) wsgiref.handlers.CGIHandler().run(application) The app.yaml file routes requests amongst different Python scripts. With a particular script, the URL list routes requests amongst handlers.

Review: app.yaml application: ae-03-webapp version: 1 runtime: python api_version: 1 handlers: - url: /.* script: index.py def main(): application = webapp.WSGIApplication([ ('/.*', MainHandler)],debug=True) wsgiref.handlers.CGIHandler().run(application) You route URLs in the app.yaml file and in the web application framework. For our simple application we simply route all URLs (/.*) to the same place both in app.yaml and in index.py.

app.yaml GET /... index.py:HandlerA() Handler B() grades.py:HandlerC() Handler D() webapp webapp The app.yaml file answers the question “which script?”. Within a particular script, the webapp routes requests to handlers.

Looking at a Handler

Inside a Handler The purpose of a handler is to respond when the framework “needs some help” We put methods in the handler for get() and post() main() GET /... webapp()MainHandler() get() post()

A Pointless Handler class PointlessHandler(webapp.RequestHandler): def get(self): logging.info("Hello GET") def post(self): logging.info("Hello POST") This handler, handles a GET and POST request and then does not do anything particularly useful. The post() and get() methods are the contact points between the webapp framework and our code.

Digression: Logging Web Application Logging is your friend Your customers will never tell you when something goes wrong - they won’t call you and tell you what happened So web applications log to a file or to a display - so you can monitor what is going on - even when someone else is using your applicaiton

You Have Seen the Log

The log from Google

Errors in the Log

In Your Program The framework logs certain things on your behalf Incoming GET and POST responses Errors (including traceback information) You can add your own logging messages logging.info(“A Log Message”) FIve levels: debug, info, warning, error and critical

WebAppplication GET /... Hello GET Hello POST... class PointlessHandler(webapp.RequestHandler): def get(self): logging.info("Hello GET") def post(self): logging.info("Hello POST")

Back to: A Pointless Handler class PointlessHandler(webapp.RequestHandler): def get(self): logging.info("Hello GET") def post(self): logging.info("Hello POST") This handler, handles a GET and POST request and then does not do anything particularly useful. The post() and get() methods are the contact points between the webapp framework and our code. Our job is to prepare the response to the GET and POST requests in these methods.

The MainHandler class MainHandler(webapp.RequestHandler): def get(self): logging.info("Hello GET") self.dumper() def post(self): logging.info("Hello POST") self.dumper() In addition to a happy little log message, the get() and post() methods both call dumper() to return a response with a form and the dumped data.

formstring = """ Zap Data: Zot Data: File Data: """ def dumper(self): self.response.out.write(self.formstring) self.response.out.write(" \n") self.response.out.write('Request parameters:\n') for key in self.request.params.keys(): value = self.request.get(key) if len(value) < 100: self.response.out.write(key+':'+value+'\n') else: self.response.out.write(key+':'+str(len(value))+' (bytes long)\n') self.response.out.write('\n') Multi-line string constant with triple quotes. Loop through parameters and print them out.

We don’t Use print Our task is to prepare the response and give it back to the framework - so instead of just printing the output, we call self.response.out.write(“Some String”) This lets the framework do something tricky (or Cloud-Like) with our response - if it so desires

Post-Cloud View The Cloud My Code Your Code My User GET

formstring = """ Zap Data: Zot Data: File Data: """ def dumper(self): self.response.out.write(self.formstring) self.response.out.write(" \n") self.response.out.write('Request parameters:\n')... The response starts with a form tag. Since this is a GET, there are no parameters displayed.

def dumper(self): self.response.out.write(self.formstring) self.response.out.write(" \n") self.response.out.write('Request parameters:\n') for key in self.request.params.keys(): value = self.request.get(key) if len(value) < 100: self.response.out.write(key+':'+value+'\n') else: self.response.out.write(key+':'+str(len(value))+' (bytes long)\n') self.response.out.write('\n')

def dumper(self): self.response.out.write(self.formstring) self.response.out.write(" \n") self.response.out.write('Request parameters:\n') for key in self.request.params.keys(): value = self.request.get(key) if len(value) < 100: self.response.out.write(key+':'+value+'\n') else: self.response.out.write(key+':'+str(len(value))+' (bytes long)\n') self.response.out.write('\n')

Multi-Part Form Data If you recall, there is a big difference between normal form data and multipart form data. The framework solves this for us. And saves us a lot of work! Normal Multi-Part

Summary We are now using the webapp framework provided by Google to handle the low-level details of the Request/Response cycle and data formats We create a Handler to handle the incoming requests and then start the webapp framework to handle the requests and call our Handler as needed In a web application, log messages are your friend!