Home > Web Front-end > JS Tutorial > body text

Mock Requests

王林
Release: 2024-09-04 22:43:09
Original
776 people have browsed it
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 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.

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 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.

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 extension.

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

  • I can 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 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!

source:dev.to
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!