DEV Community

Cover image for πŸ”₯ Never Wait for Backend Again! 3 Stupidly Simple Steps That Changed My Frontend Life
Vergil
Vergil

Posted on

54 10 11 11 13

πŸ”₯ Never Wait for Backend Again! 3 Stupidly Simple Steps That Changed My Frontend Life

Last week, I came across the article "How to Build Your Frontend Apps 10x Faster!" and found it incredibly interesting. I decided to give the techniques a try, and my development efficiency improved dramatically.

Image description

What is Mock ❓

Image description

  • In typical development environments, when we receive a requirement, both the frontend and backend teams start developing simultaneously.
  • What? You wonder if it's possible to wait for the backend to complete the entire development before the frontend begins integration? That's not feasible πŸ™… unless you own the company.
  • In reality, frontend developers with strong skills can create pages very quickly. They can complete several static pages in no time, leaving only the task of interfacing with the API.
  • At this point, data-related coding comes into play. We rely on the response from API data to handle some complex logic. However, while interfacing, we often encounter unclear API documentation, such as incorrect parameter names or unspecified required fields, exposing all kinds of minor but frustrating issues.
  • This is where learning to use the most suitable Mock data method becomes crucial. Essentially, it's a technique that allows us to obtain simulated data that matches the agreed data structure with the backend, even when the backend data isn't ready. This avoids allowing backend delays to impact our regular development process.

How to Use Mock ❓

Image description

  • Apidog is a real design-first API development platform that enables you to easily create endpoints and automatically generate mock data, simply by having a JSON structure.
  • Using Apidog's mock path is quite simple. The process involves three straightforward steps: First, obtain the JSON data structure; second, create an endpoint; and third, acquire the mock URL for use.

πŸ”₯ Step One

  • First, we need to obtain a JSON data structure. This can be achieved by communicating with the backend team to provide the corresponding data format. For instance, they might provide a JSON structure like this.
{
    "status": "success",
    "timestamp": "2024-01-20T10:30:45Z",
    "data": {
        "books": [
            {
                "id": "978-0-123456-78-9",
                "title": "Understanding Computer Systems",
                "author": "Randal E. Bryant",
                "publisher": "Technical Publishing House",
                "publishDate": "2016-01-01",
                "price": 49.99
            },
            {
                "id": "978-0-123456-78-8",
                "title": "Clean Code",
                "author": "Robert C. Martin",
                "publisher": "Prentice Hall",
                "publishDate": "2008-08-01",
                "price": 44.99
            }
        ],
        "pagination": {
            "currentPage": 1,
            "totalPages": 50,
            "totalItems": 500,
            "itemsPerPage": 10
        }
    }
}
Enter fullscreen mode Exit fullscreen mode

πŸ”₯ Step Two

  • Apidog offers a web version, allowing us to use it online without downloading anything. All you need is to register for an account.
  • Start by creating a new project. The platform supports both HTTP and gRPC, but here we'll choose HTTP. Enter your project name and click "Create."

Image description

  • After creating the project, the next step is to set up a new endpoint. Fill in basic information such as the endpoint path and name.

Image description

  • Under the "Responses" section, click on "Generate from JSON etc." and paste your JSON data. Apidog will automatically generate the correct Data Schema from the JSON. It's incredibly convenient!

Image description

  • You'll notice in the "Preview" area that it shows the content that will be mocked later. It's amazing how effortless it is.

Image description

πŸ”₯ Step Three

  • Now, we need to obtain the corresponding mock address. To do this, switch to the "Settings" tab on the left side, select "Mock Settings," and turn on the cloud mock toggle.

Image description

  • This gives us the Cloud Mock Base URL.

  • Return to the "Run" page of the endpoint. In the top-right corner, select the cloud mock environment and click "Send." You'll see in the bottom panel that the data has responded successfully. It's very cool.

Image description

  • Switch to "Actual Request" to access the real request URL. Copy it into your browser's address bar to view the corresponding mock data. This process is incredibly convenient, allowing you to easily use it directly in your projects.

Image description

  • Additionally, you can adjust the default rules for intelligent mocks or create custom rules, making it a highly powerful tool.

Image description

🌟 Final Thoughts

  • Now we've completed the Mock setup. As you can see, the process is quite simple. In practice, this approach is very user-friendly and significantly enhances the efficiency of the frontend, backend, and testing teams. As frontend developers, we should all give Apidog a try to experience this elegant mock solution.

Image description

  • The intuitive interface and powerful features of Apidog mean that even developers with minimal experience in mock data generation can quickly get up to speed, creating a more productive and efficient workflow. There's no doubt that integrating such tools into your development process can lead to more robust applications and a faster time-to-market. Give it a try and see the difference it makes!

Image of Timescale

Timescale – the developer's data platform for modern apps, built on PostgreSQL

Timescale Cloud is PostgreSQL optimized for speed, scale, and performance. Over 3 million IoT, AI, crypto, and dev tool apps are powered by Timescale. Try it free today! No credit card required.

Try free

Top comments (5)

Collapse
 
elanatframework profile image
Elanat Framework β€’

Using front-end frameworks has presented web development with great challenges.

WebForms Core is a revolutionary technology that automatically manages HTML tags through the server.

You can see the functionality of WebForms Core technology in the video below.

youtube.com/watch?v=Yp4vQ_lEd_8

Collapse
 
manvendrask profile image
Manvendra Singh β€’

You should use mswjs.io/. This way you can maintain yourocks in VCS in type safe manner.

Collapse
 
procoders profile image
ProCoders β€’

Great Article!

Collapse
 
anuragdeore profile image
Anurag D β€’

Its worth checking out mockoon.com/

Collapse
 
ismailkamil profile image
Ismail Kamil β€’

Thanks for your response to my article! ❀️

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

πŸ‘‹ Kindness is contagious

Engage with a sea of insights in this enlightening article, highly esteemed within the encouraging DEV Community. Programmers of every skill level are invited to participate and enrich our shared knowledge.

A simple "thank you" can uplift someone's spirits. Express your appreciation in the comments section!

On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found this useful? A brief thank you to the author can mean a lot.

Okay