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!
â¤ď¸