How backend devs can save an hour a day in local development & testing
Tags: api, backenddevelopment, microservices, kubernetes
Published: 2022-08-05 07:25:29

---
title: How backend devs can save an hour a day in local development & testing
published: true
date: 2021-12-12 15:24:58 UTC
tags: api,backenddevelopment,microservices,kubernetes
canonical_url: https://requestly.com/blog/local-api-development-and-testing-productivity-for-backend-engineers/
---

In my previous organisation, where I worked as a backend engineer, during development of any feature or even a small bug fix, we used to first develop & test the changes on the locally setup MicroService. After that, we deploy the changes on the Kubernetes stage cluster in an isolated namespace, which has all the other services deployed too. The deployment pipeline usually took around 5–10mins to completely deploy all the services. After the stage is setup, we change the API gateway in our debug app to point to the stage environment so we can test the changes end-to-end on the app.

This often requires multiple cycles and sometimes unstable stage environment makes the entire development & testing very frustrating. We often found ourselves fixing the configuration on stage environment and then testing the changes. This is how the process looked like before:

![](https://cdn-images-1.medium.com/max/1024/1*098hKkde4Hx8BvIid9x9iQ.png)
_current api development & testing process_

#### Limitations

- It was very time consuming.
- Multiple deployments required after every change/commit.
- Debugging using breakpoints in IDE was not possible.
- Maintaining a stage environment is very hard. Our Staging environment lacked a lot of data, stability issues so every-time testing on stage was pain.

Almost every developer uses this tedious process to test out the changes. As this process is time consuming, sometimes we miss certain edge cases, as a result multiple times it had also led to downtimes 😢 and bugs in production.

**We tried telepresence too for local testing** , but no one ended up using it due to the tedious process in setting it up.

### Introducing Requestly 💪

Requestly is a cross-platform developer tool to intercept all local network traffic and gives request level granular control to modify individual pieces of an API request. Requestly can be leveraged here to reduce the development & testing time and also testing different corner cases.

![](https://cdn-images-1.medium.com/max/1024/1*FPAOE8DT0ys1GFQw4M-Plw.png)
_Requestly — Detailed View_

### How Requestly can help?

Using [Requestly desktop app](https://requestly.com/desktop), you can intercept all traffic from your Android & IOS debug apps. Then you can create a traffic modification rule (simply rule) to redirect a particular endpoint/service to your local machine and not to production endpoint (A No-Code solution for the Coders) This lets users instantly test out any changes directly against production environment **without depending on the staging environment**.

On top of this, you can instantly test out how the app reacts when the response of an API changes, without making any changes to the code. You can mock API responses using Requestly. You can also test for 4xx, 5xx scenarios, add artificial latency to your APIs and test your app.

So this is how the process looks like now:

![](https://cdn-images-1.medium.com/max/1024/1*ZwrK6urGDesweiSFXdGzKg.png)

#### Example — Use Search APIs from local in debug app

For example, If you are working on Search service and want to test Type To Search experience, this setup can be really life saviour. For this you can configure [a Replace Rule in Requestly](https://developers.requestly.io/http-rules/replace-strings/) like this

```
Replace: https://api2.grofers.com/v5/search 
With: [http://localhost:5000/v5/search](http://localhost:5000/v5/search)
```

Here’s how the flow of data look like —

![](https://cdn-images-1.medium.com/max/1024/1*yciTCKlsDlkdu9_ORn8r5Q.png)
_Serve a single API traffic from local server using Requestly while getting all traffic from Production_

#### Benefits

- Changes instantly reflected on app
- No multiple deployments cycle required.
- Test different edge cases which only exist on production. **Deploy on production with confidence.**
- Debugging with breakpoints in your favourite IDE is now possible
- Minimize dependency on Stage environment

### Configuring Requestly (Step by Step guide)

Now you know the benefits of using Requestly in your local API development & testing. It’s time to set up Requestly. Here’s step by step guide.

#### Step1 — Download Requestly Desktop app

Go to [https://requestly.com/desktop](https://requestly.com/desktop) and download the desktop app for your OS — Mac, Linux & Windows.

#### Step2 — Install Certificate & Configure Proxy in Android/IOS Debug App

![](https://cdn-images-1.medium.com/max/1024/1*legrPirmlYX69asAp2lYhQ.png)

At this point, you should be able to see the traffic from your debug app in the Network Traffic table.

#### Step3: Setup Redirection Rule in Requestly

![](https://cdn-images-1.medium.com/max/1024/1*v-GujOV6JI1-dDOgUhN5hQ.png)
_Redirect Rule in Requestly_

Redirecting v5/search endpoint from Production to local server

#### Step4: Add Preset headers (If required)

Click on Create New Rule and then Select Modify Headers to add additional headers to the request which Kong adds in the production environment So that your [localhost](http://localhost) end point also receive the same headers.

![](https://cdn-images-1.medium.com/max/1024/1*lMYx9QQJpjS6w8vCrW_sfA.png)
_Add Request headers using Requestly_

That’s it! You should be able to **test features like TypeToSearch directly in debug app against the production** K8s cluster utilising the production data on ElasticSearch and other production configurations.

**Please note** we don’t intend to discourage testing in the stage environment. We just want to emphazise that you can avoid multiple cycles of deployment on stage during the development. Ofcourse, the ideal practice should to test end to end on local, then doing testing on stage and then deployment on production.

Happy testing! By [Sahil Gupta](https://www.linkedin.com/in/sahil865gupta/)

_Originally published at_ [_https://requestly.com_](https://requestly.com/blog/local-api-development-and-testing-productivity-for-backend-engineers/)_._