How to easily debug your network code 🛰️
Hi 👋
Happy new year 🥂
This is my first newsletter of the year, and I’m super happy to share that it will be sent to more than 3,100 subscribers 🥰
A couple of months ago, I did a livestream to show how a macOS tool called Proxyman can make debugging network code much easier.
But since the livestream is a bit long to watch, I also wanted to do a written recap of the features I’ve found the most enjoyable!
Before we deep dive into the topic, full disclosure: this email has been sponsored by Proxyman 😌 (#advertisement)
(and I wanna thank them for their support in sponsoring my content ❤️)
#01 – Inspecting Network Traffic
So what’s Proxyman?
It’s a macOS app that allows you to monitor and manipulate all the network traffic that goes in and out of other apps:
This basically means that a tool like Proxyman allows you to debug your network code without needing to make any change to your codebase 👍
So you can run your iOS app, either in the simulator or on a real device, and you’ll be able to see all the network calls your app is making.
#02 – Exporting a Request a cURL
You’ve probably experience that reporting a bug to a back-end team can be challenging!
The back-end team will ask you for a way to reproduce the faulty request, and this can be time consuming to generate with your iOS code 😔
And this is where a really nice feature of Proxyman can help you save a lot of time and effort: exporting a request as cURL.
As its name suggests, this feature will export any request to a cURL syntax that can be run from the terminal:
If you share this with your back-end colleagues, they will have all the information they need to reproduce the faulty request ✌️
#03 – Breakpoints: Observing and Modifying Network Traffic
We all know how breakpoints work in Xcode: you set a breakpoint on a line of code and it triggers when the execution flow reaches that line.
As it turns out, Proxyman allows you to do the same thing but for network requests!
You can set a breakpoint that will trigger whenever a network request that matches a rule is sent:
But these breakpoints allow you to do more than just observing: you can also modify network traffic!
For instance, you can dynamically modify the content of the request that’s being sent:
This is a really great feature when you want to test a different request, but don’t want to spend time implementing the change in your iOS code!
(in this example I showed you how to modify a network request, but you can of course also do the same with the response 👍)
#04 – Map Local: Serving Local Data to a Network Request
Now let’s talk about what might be my favorite feature of Proxyman: the Map Local feature.
In a nutshell, this features allows to intercept a network request and immediately generate a response, using the content of a local file:
What’s amazing about this feature is that it allows you to implement a mocking feature without making any change to your iOS code 🤯
And if needed you can go even further, because it’s also possible to:
map the response to a remote endpoint, which is very useful if you want to redirect a specific request to a different back-end environment
write scripts that will dynamically modify the request and/or the response
#05 – Network Conditions: Simulating a Bad Network
If you work a lot with the iOS simulator, you’ve probably been frustrated that, unlike with a real device, it’s not possible to simulate a bad network.
The best you can do is to turn off your Mac’s networking all together, but this isn’t great as it will also cut off all other apps from the network.
Once again, this is a problem that Proxyman solves: it allows you to set specific network conditions for a specific HTTP host.
This way, you can simulate a bad network just for the traffic between your app and its back-end:
That’s it! These are the 5 features of Proxyman that I particularly enjoy!
If you want to see them in action, click on the titles for a live demo 🍿
And if you’re curious to watch the full livestream, here’s the link!
That’s all for this email, thanks for reading it!
If you’ve enjoyed it, feel free to forward it
to your friends and colleagues 🙌
I wish you an amazing week!
❤️