Skip to content

Latest commit

 

History

History
22 lines (13 loc) · 845 Bytes

modifyingresponses.rst

File metadata and controls

22 lines (13 loc) · 845 Bytes

Using middleware to modify response payload and status code

Please carefully read through middleware alongside these tutorials to gain a high-level understanding of what we are about to cover.

We will use a python script to modify the body of a response and randomly change the status code.

Let's begin by writing our middleware. Save the following as middleware.py:

middleware.py

The middleware script randomly toggles the status code between 200 and 201, and changes the response body to a dictionary containing {'foo':'baz'}.

modify.sh

As you can see, middleware allows you to completely modify the content of a simulated HTTP response.