Creating a test HTTP service

Developing code that interoperates with an outside service can be frustrating. We're going to need to send a lot of bad or test data to the service while writing and debugging our code; we don't want to do so against a production service, and a "test mode" is not always available. Automated tests can use a Mock object to patch out network requests altogether, but during development, it's nice to be able to see what's actually going to be sent out to the web service.

Let's implement a very simple HTTP server that will accept our requests and print out information about what it receives. We can do this using the Python standard library's http.server module.

The module documentation shows the following example of ...

Get Python GUI Programming - A Complete Reference Guide now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.