Quickly switch between local mocks with Charles

Inevitably, the API you’re developing with isn’t fully functional when the sprint starts or you aren’t given user accounts that cover all the possible cases you need to handle. You could add a breakpoint in Charles and change the response every time… but read on for a better way!

Charles is a powerful tool for inspecting HTTP requests coming from your devices. I’m going to assume you’ve used Charles a bit before reading this article 😉

I’m actually lactose intolerant, but I use Charles anyway

Developers and QA engineers have used Charles to tailor responses to their needs throughout every project I’ve worked on. Breakpoints are the most common way you can mocking responses: add a breakpoint on the request in question and when the response comes back manually modify the payload before allowing Charles to send it to the client device. This is tedious to do as often you’ll want to re-test with the same response multiple times, or the app’s internal request timeout will occur before you figure out how to modify the payload.

Map Local

Intermediate Charles users can harness the power of “Map Local”: for a given endpoint, return the contents of a file on disk rather than the payload returned by the remote server. You can add a local mapping from the right-click menu of a request or from the Tools > Rewrite menu item: