Apidog

All-in-one Collaborative API Development Platform

API Design

API Documentation

API Debugging

API Mock

API Automated Testing

Sign up for free
Home / Tutorials / How to Mock Online APIs without Setting Up a Server

How to Mock Online APIs without Setting Up a Server

Mocking JSON data offline is common, but not sufficient for scenarios requiring online data in apps. Running a mock server on the cloud is difficult for front-end developers. A new free and easy way to start a mock server on the cloud is available.

There are many approaches to mock JSON data and use it offline. But if you need some online data in your app, you'll have to run a fake server in your own cloud server.
That's not easy, especially for front-end developers. But now, there is a fantastic way to start a mock server on the cloud, easily and free.

Why Mock APIs Online

In local development, offline mock data is enough for front-end developers. But there are some common scenarios where offline mock data is not good enough.

Scenario 1: Team Shared Mock Data

Some data structure is complicated, maybe with many fields or following complex schemas. If several developers need the same mock API, the best solution is to build one online mock server that everyone can visit.
For teams, shared online mock data would accelerate their development a lot. Mock data can be defined only once.

Scenario 2: APIs Under Development

In many teams, APIs are not designed well at the beginning. An initial specification of how the API responses should look is likely to change while it is developed for real. An offline mock data will soon be different from the real API responses.
So, online mock data following backend API specifications would be great.

How to Mock Online APIs

Previous articles as well as introduced how to mock dynamic data on a local server rapidly in the tool Apidog.
And now surprised to find that mocking on a cloud server is also easy and free!

Step 1: Import API Definitions

API documentation is necessary. OpenAPI (Swagger) is best, and any other format is OK, too.

Create a new project in Apidog.

Create a New project

Go to "Settings"-"Import", and drag your API file in.

Import API

More than ten formats of API documentation are supported. Click "Next" and your API will be imported.

Step 2: Turn on the Mock Cloud Server

Go to "Settings"-"Feature Settings"-"Mock Settings", and turn on the "Cloud Mock" switch.
Cloud mock can be accessed open, or you can set a token for it.

Turn on Cloud Mock

Step 3: Get the Mock URL

Click an API in Apidog. You'll see an API definition page, in which there is a section named "Mock". Copy the URL in the "Cloud Mock" part which starts with "mock.apidog.com".

Mock URL

Paste it into your browser. That it's done! You'll see a mocking JSON!

Mocking JSON

A "city" field is filled by a city name, an "id" field is filled by an integer, and "status" is a enum field.

Now you can use the API data in your app, and anyone in the team can access this URL to get data. Still, you don't need to write any scripts. Data in all fields are generated automatically.

And when you click "reload" in the browser, the data will refresh.

Mocking JSON

APIs Under Development: New Tool

This approach solved the team-shared mock data scenario. But if the API is still under development, how can the other developers get the latest mock data?

The solution is also in Apidog. Apidog is an all-in-one API developing toolkit, so the backend developers can use it to debug the APIs like in Postman and specify APIs like in Stoplight. Apidog can synchronize Swagger automatically so API specifications can be kept the latest. When API specifications change, the online mock data changes synchronizing.

It's a perfect API for developing a toolkit for teamwork. You can register or download Apidog here.

Join Apidog's Newsletter

Subscribe to stay updated and receive the latest viewpoints anytime.