Home >Web Front-end >JS Tutorial >Mock Requests
Every front goes through the need to mock endpoint requests, sometimes because the back has not finished its work yet, 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.
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 in case 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 a problem with the API.
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 extension.
Here was the solution to my problem
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.
These are the cool and simple to use things. If you already know the extension and have other tips, share it here.
Hugs!
The above is the detailed content of Mock Requests. For more information, please follow other related articles on the PHP Chinese website!