This tutorial explains how to measure CO2 emissions from your APIs. Step CI is a free open-source API testing tool that you can install on your system. Or, there is an online version available where you can try this now as well. It follows a YAML like syntax and in that, you can specify CO2 as a returning parameter. After you test and make an API request with it, it will show you how much carbon emission was caused by that.
Step CI shows you the carbon emission in terms of grams. You can see that in the API response that it returns. You can make the API request either from your command line or online. There is a specific YAML syntax that it follows. You can even batch your requests if you have some knowledge of programming.
The calculation algorithm that is being used by Step CI is provided by Sustainable Web Design. It is kind of hard to understand how this works underneath but it can generate a very close carbon footprint that you can analyze. The algorithm is kind of tricky to understand but you can follow the above link to read about it in more detail.
How to Measure CO2 Emissions of APIs for Free?
Step CI can be installed using Node.js on your PC and its binary will be added to the PATH system environment variable. But the simplest way is to use its online hosted version. There you don’t have to sign up or register. You can reach the homepage here and the main interface will appear like this.
Click on Get started and then just enter the YAML like syntax in the box. Just make sure that you change the
url variable with the API endpoint for which you want to calculate the carbon footprint.
version: "1.1" name: Emission Check tests: example: steps: - name: GET request http: url: https://example.com method: GET check: co2: - lte: 0.05 # in grams
Now, you just click on the play button and it will only take a few seconds to show you the result. It will show you the result of the API as well as the calculated carbon footprint. You can see that in the screenshot below.
This way, you can now calculate or measure carbon footprint for any API. If you use the command line tool then you can even do this batch mode. Or, for a single endpoint, you can just make the requests in the online playground tool that it provides to you already.
If for some reason, you want to know the carbon footprint of an API endpoint then you can easily do that. With Step CI, it is just a piece of cake and it all takes a few seconds. Many computing environments including Google’s are now turning to green energy and it is a good thing. And if you want to test if your provider is really using green energy, a quick way of doing that would be measuring the Carbon footprints. And Step CI will help you with that for free.