Ever been faced with an old website that needs an upgrade best done incrementally? At http://www.parsonsmatt.org/2016/06/24/take_over_an_api_with_servant.html, Matt Parsons describes an approach to incrementally take over an old API using Servant and a reverse proxy, which is worth a read!
On occasions, though, your predecessor may not have written a considered, documented API. Sometimes all that exists is a sprawl of tangled php, html and javascript that just about works, until there’s a change in business logic and the code gets touched — at which point everything breaks. Unlike the example in Matt’s post, it has an index.php
route with all the pages at index.php?page=<PAGE>
, instead of using path pieces separated by solidus.
Matt’s approach works in this case too, and we don’t even need to change the haskell server he supplies! We simply change how we use the reverse proxy and add some url rewriting middleware.
This example copies Matt’s woofing and meowing server, for simplicity of comparison. His code is on github, as is mine.