"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > Mock Requests

Mock Requests

Published on 2024-09-17
Browse:128
Calm down committer king, I'm not going to talk about JSON-Server, but it's worth staying!

Every front goes through the need to mock endpoint requests, sometimes because the back has not yet finished its work, sometimes to debug and simulate specific situations and this is very common in everyday life.

Yes, JSON-Server is incredible and very simple to use, but a few days ago I experienced a problem that was very specific, and I ended up discovering an incredible browser extension.

The Problem

Mock Requests

First I'll talk about the problem I had, and you'll understand why JSON-Server wouldn't work in this situation.

In the application I had to consume two different endpoints. A first one that loaded some information in the dashboard, but one of the cards in that dash opens a Modal, which depended on another endpoint.

We had some treatments if the API was out, but at a certain point I encountered an unforeseen problem with a delay in the return of the second API. It shouldn't be like this, but it was!

The first Dashboard endpoint returned the message, but the modal API took a few seconds, which was enough time for me to open the modal and have nothing in the table.

It took me a while to understand what was happening, until I realized that it was an API problem.

But then a new problem arose!!

How to simulate this?
How to mock a delay in the return.

I started researching and found Tweak, an extension for Chrome (and others), which is very simple and powerful.

My idea is not to give training, I just want to share one of the functions that caught my attention in this area.

Delay in response

Here was the solution to my problem

Mock Requests

Now the Tweak starts monitoring the URL and when it is requested, (1) it takes care of managing the time I determined to return the request, and (2) I can mock the data in the body of the response.

Other features

  • Can I turn a certain mock on or off
  • I can mock not only data, but errors too, just change the status.
  • I can mock the data very simply, directly in the extension
  • I can mock different methods (GET, POST...)

These are the cool and simple to use things. If you already know the extension and have other tips, share here commiteiro.

Hug!

Release Statement This article is reproduced at: https://dev.to/andpeicunha/mock-requests-3fa4?1 If there is any infringement, please contact [email protected] to delete it
Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3