Reverse engineer an API using a web proxy
Tags: postman, api, proxy
Published: 2019-01-03 20:09:34

---
title: Reverse engineer an API using a web proxy
published: true
description: Gain a deeper understanding of a public or private API, especially for ones that aren’t well-documented
tags: postman, api, proxy
canonical_url: https://medium.com/postman-engineering/reverse-engineering-an-api-403fae885303
cover_image: https://cdn-images-1.medium.com/max/2000/1*Y2et8qgv-rmXlEyMUaTBJg.png
---

When you think about reverse engineering an API, perhaps corporate espionage or something legally or ethically questionable comes to mind. Hackers gonna hack. However, there’s also legitimate reasons for reverse engineering an API.

## Why reverse engineer an API
APIs aren’t always documented. When you’re debugging an API, you can diagnose and resolve issues more quickly when you can visualize all the data that is sent and received. Doing this allows you to gain a deeper understanding of an API.

> [Reverse engineering](https://en.wikipedia.org/wiki/Reverse_engineering), also called back engineering, is the process by which a man-made object is deconstructed to reveal its designs, architecture, or to extract knowledge from the object.

Knowing how an API actually behaves enables you to identify flaws and security vulnerabilities [like accidental data leakage](https://medium.freecodecamp.org/reverse-engineering-apis-coffee-meets-bagel-2eda71295613). This also performance tests your API so you can isolate bottlenecks that could benefit from additional caching and compression.

Of course, there’s also selfish reasons for reverse engineering an API.

## Selfish reasons for reverse engineering an API
* Accessing a service programmatically [that doesn’t offer a public API](https://blog.tendigi.com/starbucks-should-really-make-their-apis-public-6b64a1c2e923)
* Creating an interface that suits your needs because [theirs just ain’t cutting it](https://www.toptal.com/back-end/reverse-engineering-the-private-api-hacking-your-couch)
* Contribute to a feature that the engineering team is slow 🐌 to deliver
* Hack with the hopes that you’ll dazzle the engineering team and they’ll offer you a job
* [Order extra bacon on your pizza](https://news.ycombinator.com/item?id=14758500) when the available app limits you to a sub-optimal amount of bacon
* Cheat at games — there’s [an entire subreddit dedicated to this](https://www.reddit.com/r/REGames/) among [others](https://www.reddit.com/r/ReverseEngineering/)
* Scale up your catfishing side business by [unleashing chatbots on popular dating apps](https://gist.github.com/rtt/10403467)

When you’re reverse engineering a private API that isn’t yours, make sure to check the terms of service. Some developers wear their cease and desist orders like a badge of honor, but you might get sued or banned from their services.

## What is an HTTP/S proxy?
A [web proxy server](https://en.wikipedia.org/wiki/Proxy_server) is like a middleman that sits between your client application and the server. The web proxy is a substitute server that can intercept HTTP traffic between a web browser and the website’s real server.

> It’s all there! Black and white, clear as crystal!
— Willy Wonka, The Chocolate Factory

### Reasons to use a web proxy
* Monitor and eavesdrop on HTTP network traffic by recording and displaying all traffic between your client and server
* Hide your public IP address while browsing websites and to access blocked content
* Filter or redirect requests to limit access to content or optimize systems performance

![Postman is a proxy that captures the HTTP/S request](https://cdn-images-1.medium.com/max/2000/1*W5CE9hV6_G_ivcU9UuYlHw.png)

## Free web proxy tools
* **[Postman](https://www.getpostman.com/)** is a free tool with [a bunch of different proxies](http://blog.getpostman.com/2017/09/29/client-proxy-settings-in-postman/), including [a built-in proxy](https://learning.getpostman.com/docs/postman/sending_api_requests/capturing_http_requests) to capture HTTP requests in the native apps for Mac, Windows, or Linux
* **[Mitproxy](https://mitmproxy.org/)** is an open-source proxy with a command line interface, web interface, and Python API
* **[Fiddler](https://www.telerik.com/fiddler)** is a free web debugging proxy with support for a wide variety of browsers, systems, and platforms
* **[Burp](https://portswigger.net/burp/documentation/desktop/tools/proxy)** has a free community edition of a web proxy server that lets you view and modify requests and responses

The remainder of this article will focus on how you can use Postman to intercept the traffic between your client and server.

---

## A Postman recipe for reverse engineering an API

It’s time to get our hands dirty, sniffing and inspecting to our heart’s content. First, we’ll import a single request into the Postman app. Then we’ll use Postman as a proxy to capture a stream of HTTP/S requests from a variety of clients like a desktop web browser, a mobile device, and an Electron app.

{% youtube 2VKVPB5USgU %}

To follow along in Postman, click the orange **+New** button in the top left of the Postman app. Under the [Templates](https://www.getpostman.com/docs/v6/postman/launching_postman/newbutton#templates) tab, search for **Reverse engineering an API**, and import the sample collection into your instance of the Postman app.

![Import this collection and follow along with these examples](https://cdn-images-1.medium.com/max/1600/1*s10zVLqch6xLcdwmtqZdjw.png)

Read through the descriptions in the Postman app for details, or check out the [web documentation](https://documenter.getpostman.com/view/1559645/Rzn9uMQk) for step-by-step instructions and screenshots.

### Import a single request
If you want to inspect a request in Postman, here’s a super simple way to import it as [cURL](https://curl.haxx.se/docs/manpage.html) from your browser. In this example, we will use [Chrome DevTools](https://developers.google.com/web/tools/chrome-devtools/) to inspect and select a request. You can follow similar steps when using other web browsers.

![Copy the cURL request from Chrome DevTools](https://cdn-images-1.medium.com/max/1600/1*cXBMjFq2g5N7-2SyElYXGw.png)

![Paste the cURL request as raw text in Postman](https://cdn-images-1.medium.com/max/1600/1*_2ENwXUm9rONc8X3yNBAqg.png)

### Inspect a stream of requests
If you want to inspect a stream of requests from your client, you can use the Postman built-in proxy to capture these requests. Postman [has a bunch of different proxies](http://blog.getpostman.com/2017/09/29/client-proxy-settings-in-postman/). In this scenario, we’ll rely on [the Postman built-in proxy](https://learning.getpostman.com/docs/postman/sending_api_requests/capturing_http_requests) in the native apps for Mac, Windows, or Linux. You can capture requests sent from your client, like a desktop web browser, mobile device, or an Electron app.

You can pipe this stream of requests to your [Postman History](https://learning.getpostman.com/docs/postman/sending_api_requests/history) and save them to a [Postman Collection](https://learning.getpostman.com/docs/postman/collections/intro_to_collections). Then you can revisit these requests for inspection at a later date, or [share them with a teammate](https://learning.getpostman.com/docs/postman/collections/sharing_collections).

Currently, the Postman built-in proxy in the native apps only captures HTTP request traffic. Fortunately, most websites have HTTP Strict Transport Security (HSTS) enabled for an additional layer of security. Unfortunately, this means the Postman built-in proxy cannot capture requests sent over HTTPS if the website has HSTS enabled.

> Note: As of the publication of this article, the Postman built-in proxy captures HTTP traffic, but not traffic from HTTPS websites with HSTS enabled. [Interceptor integration](https://trello.com/c/Ewv9DGhh/79-interceptor-integration) and [HTTPS proxy](https://trello.com/c/S4E7egzO/78-https-proxy) is slated for development in the [Postman roadmap for developers](https://trello.com/b/4N7PnHAz/postman-roadmap-for-developers).

---

## A final thought about reverse engineering an API
This recipe is just the tip of the iceberg of how you can sniff and inspect HTTP traffic to start understanding what’s going on under the hood. For tougher nuts to crack, you may have to dig into [SSL certificate pinning](https://en.wikipedia.org/wiki/Transport_Layer_Security#Certificate_pinning), spoof particular client attributes, or learn how to sign and authenticate more complex requests.

Although these tools and methods are powerful and can be used for selfish reasons, they can and should be used for good.

> Be excellent to each other.
— [Bill S. Preston, Esq.](https://www.imdb.com/title/tt0096928/)

Tools like Postman can enhance the visibility of client requests, making them easier to replicate and tweak, so you can diagnose and resolve issues faster. Ultimately, this will help you gain a deeper understanding of a public or private API, especially for APIs that aren’t well-documented.

**This article was originally posted on the [Postman Engineering blog](https://medium.com/postman-engineering/reverse-engineering-an-api-403fae885303)**