In any distributed system development, various pieces of an application gets developed by multiple teams from different parts of the geography. This is a OK till you hit a roadblock when you cannot proceed until another team finishes their work and provide the data you need. In today's microservices design model this is even more relevant where you need a dependent service to return the data you need so that you can complete your work.
This type is scenario is inevitable and you cannot help but rather have to live with it. So what to do? 😒
Mocking!! Yes you are right. Why not mock the data you need to finish your work and later just do the plumbing work with the actual service when it's up and ready to throw back actual data. This is a great idea where teams can work on their own schedule without waiting and running after each other.
In Azure, when it comes to mocking, developers often fall back on API Management to implement this with the help of APIM polices. But why going for such costly idea where the need is only to mock data when you can use your other friend Logic Apps to achieve the same. Let's check it out 👍
Scenario:
We need to get the employee details from the database service (developing by the back-end team) by passing the employee code. But the back-end team is not yet there and hence we need to mock the employee details.
Let's get started.
Define an http endpoint where we will send the employee code as below
Add a new action and search for the HTTP action
Fill the details as per your requirement. In my case it's a GET call with the following details.
As mentioned the URI is the service that's getting developed by the backend team which is not yet ready. So, in this action we have to inject out mocking logic.
Click the "..." eclipse at the top right section of the action and select "Static result (Preview)" from the context menu. Yeah it's preview but works just fine. Go ahead!
Enable the Static result to get the following window. The default selections are good to go for our mocking purpose
But strangely there's no place to provide the static json response content here. Don't worry! It's there but we need to tweak a bit 😉
Hit the JSON mode icon to switch to the JSON view mode as below
Now here in the outputs section paste your return JSON in a body tag as below. I just need the employee first_name, last_name , "dept" and "rank" from the database service. So, I have mocked that piece as the back-end service is not yet ready and I can continue with my development 😃
Hit Done as return to the workflow. Now you will find a new icon added to the action which denotes that this action has a static result configured
As a last step let's add an "Response" action in the workflow and return back the employee details to the caller.
Save your logic app.
Done! let take a bird's eye view of our logic app workflow. This will help you to match if you are doing it in parallel along with this article
Testing time! Copy the http endpoint from the trigger (first action) and paste it in any rest client to make the call. I have used postman rest client as below. Hit Send and get your static result back.
Isn't that great!