How to use this module

This module provides Middleware to rewrite URL paths. It also provides
functions that will convert a Request to a modified Request.
Both operations require a function that takes URL parameters and
headers, and returns new URL parameters. Parameters are pieces of URL
paths and query parameters.

A note on semantics

Versions of this library in wai-extra ≤ 3.0.16.1 exported only
rewrite and rewritePure and both modified rawPathInfo of the
underlying requests. Such modification has been proscribed. The
semantics of these functions have not changed; instead the recommended
approach is to use rewriteWithQueries and rewritePureWithQueries.
The new functions are slightly different, as described in the section
on upgrading; code for previous library versions can be upgraded with
a single change, and as the type of the new function is different the
compiler will indicate where this change must be made.

An example rewriting paths with queries

Let’s say we want to replace a website written in PHP with one written
using WAI. We’ll use the
http-reverse-proxy
package to serve the old
site from the new site, but there’s a problem. The old site uses pages like

index.php?page=page

whereas the new site would look like

index/page

In doing this, we want to separate the migration code from our new
website. So we’d like to handle links internally using the path
formulation, but externally have the old links still work.

Therefore, we will use middleware (rewritePureWithQueries) from this
module to rewrite incoming requests from the query formulation to the
paths formulation.