Functional Python Programming

(Wang) #1

A Functional Approach


to Web Services


We'll step away from Exploratory Data Analysis and look closely at web servers and
web services. These are, to an extent, a cascade of functions. We can apply a number
of functional design patterns to the problem of presenting web content. Our goal is to
look at ways in which we can approach Representational State Transfer (REST). We
want to build RESTful web services using functional design patterns.


We don't need to invent yet another Python web framework; there are plenty of
frameworks to choose from. We'll avoid creating a large, general-purpose solution.


We don't want to select among the available frameworks, either. There are many,
each with a distinct set of features and advantages.


We'll present some principles that can be applied to most of the available frameworks.
We should be able to leverage functional design patterns for presenting web content.
This will allow us to build web-based applications that have the advantages of a
functional design.


For example, when we look at extremely large datasets, or extremely complex
datasets, we might want a web service which supports subsetting or searching.
We might want a web site which can download subsets in a variety of formats.
In this case, we might need to use functional designs to create RESTful web services
to support these more sophisticated requirements.


The most complex web applications often have stateful sessions that make the site
easier to use. The session information is updated with data provided via HTML
forms or fetched from databases, or recalled from caches of previous interactions.
While the overall interaction involves state changes, the application programming
can be largely functional. Some of the application functions can be non-strict in their
use of request data, cache data, and database objects.

Free download pdf