The HTTP request-response model

The HTTP protocol is nearly stateless: a user agent (or browser) makes a request and the server provides a response. For services that don't involve cookies, a client application can take a functional view of the protocol. We can build a client using the http.client or urllib library. An HTTP user agent essentially executes something similar to the following:

import urllib.request
def urllib_demo(url):    with urllib.request.urlopen(url) as response:        print(response.read())urllib_demo("http://slott-softwarearchitect.blogspot.com")

A program like wget or curl does this kind of processing using a URL supplied as a command-line argument. A browser does this in response to the user pointing and clicking; the URL is ...

Get Functional Python Programming - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.