Skip to content

Instantly share code, notes, and snippets.

@dbaynard
Last active August 14, 2016 22:51
Show Gist options
  • Save dbaynard/c844d0df124f68ec8b6da152c581ce6d to your computer and use it in GitHub Desktop.
Save dbaynard/c844d0df124f68ec8b6da152c581ce6d to your computer and use it in GitHub Desktop.
Incremental API takeover

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.

Setup

Rewriting paths

Modifying requests from reverse proxy

Conclusion

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment