Fake JSON API

Access JSON APIs with generated fake data ๐ŸŽญ

Create Your Own Fake JSON API

This editor allows you to create a fake JSON API with your own fake data. Scroll down for ready-to-use examples of different fake APIs that you can use.

If you want more features that allow you to create multiple API endpoints you can use our tool Mocki. Mocki enables you to generate fake data, simulate errors, delays and much more.

Ready to Use Fake APIs

Below we have created APIs that serve test data for you to use. We created them with the form above. If you want to create your own endpoint instead of using ours feel free to do that.

Users

Users are normally one of the most fundamental components for a lot of web applications or apps. Therefor we will start out by using some endpoints providing a fake JSON API for users.

List users

A simple list of users. Call the endpoint we have prepared below to get started.

URL: https://api.mocki.io/v1/b043df5a

To test the request you can open you terminal and use cURL. You will receive you fake JSON data back as a list of users shown below.

cURL

curl https://api.mocki.io/v1/b043df5a

Response:

[
  {
    "name": "Lennart Johansson",
    "city": "Stockholm"
  },
  {
    "name": "Karl Eriksson",
    "city": "London"
  },
  {
    "name": "Pekka Hartikainen",
    "city": "Helsinki"
  },
  {
    "name": "Mia Svensson",
    "city": "Berlin"
  }
]

Get user

If you want to simulate a detail request for a single user you can create another endpoint in the form above. Or just use the one we have provided below.

URL: https://api.mocki.io/v1/ce5f60e2

cURL

curl https://api.mocki.io/v1/ce5f60e2

Response:

{
   "name":"Lennart Johansson",
   "city":"Stockholm"
}

Todos

Many tutorials ang getting started guides consist of TODO applications. Therefore we will now create some more fake JSON endpoints covering those cases. You could for example use the endpoints below when doing a tutorial on some new programming language you are trying to learn.

Get Todos

This list endpoint returns three TODOs as response.

URL: https://api.mocki.io/v1/13f44462

cURL

curl https://api.mocki.io/v1/13f44462

Response:

[
   {
      "title":"Clean kitchen",
      "description":"Don't forget the are under the sink!!"
   },
   {
      "title":"Call Eric",
      "description":"Remind him to do his taxes"
   },
   {
      "title":"Water flowers",
      "description":"Don't forget the ones in the garden!"
   }
]

Get Todo

If you need a single todo you can use this endpoint instead. It returns one mocked todo.

URL: https://api.mocki.io/v1/0350b5d5

cURL

curl https://api.mocki.io/v1/0350b5d5

Response:

{
   "title":"Clean kitchen",
   "description":"Don't forget the are under the sink!!"
}

Faking an entire JSON API

When you want to fake JSON responses for an entire API it is normally called a mock server. It requires a bit more than the endpoints we provided above. Normally you want to fake several endpoints returning fake JSON data. With Mocki you can easily do this as it lets you create several fake endpoints under the same URL but with different paths.

If you for example wanted to mock the 4 endpoints provided above in 1 single API it would require the following endpoints.

 https://api.mocki.io/v1/users
 https://api.mocki.io/v1/users/12345
 https://api.mocki.io/v1/todos
 https://api.mocki.io/v1/todos/12345

When logged into Mocki you can do this by using our API editor. It lets you select response code and data to return for each endpoint. There are also more advanced features.

Testing code with a fake JSON API

Developing a fake API can be useful for testing purposes as well. Let's say you have two different systems talking to each other. When developing one of the systems locally you might not be able to start and run the other system on your developer machine. This is where a fake JSON API can come in handy. You could point all calls to the second system over to your fake API instead. If the fake API returns the expected JSON responses then we can make sure that the functionality of the system we develop locally is doing what it is supposed to do.

Version control your fake API

Version control is fundamental in the developer lifecycle. It makes it easy to track changes in your code and if need be revert to previous versions. A rather new concept is to put your mock specifications inside your version control as well. If you have an Open API specification it's possible to put that inside a repository and track all the changes to the specification. There are a lot of services available that base their functionality upon an Open API specification. Mocki for example can get your specification from GitHub and automatically build a fake JSON API from it. Mocki will be notified if you change the file in the future and will update the fake API.

Conclusion

So lets draw some conclusions from this! A normal use case for faking an API is when frontend developers might start working without a proper backend present. In that case the frontend developers are interested in one URL which reflects the backend. It would be very hard to use one URL for each endpoint. Therefor it's more convenient to use a tool like Mocki where you can easily structure and create an entire fake JSON API.

Another important aspect of faking an API is to use a real webserver. You could for example go ahead and create a local JSON file, store all you data in the file and the read that data on startup. You would have the data in memory and could use it. But it would not properly reflect a mocked HTTP server. You have to decide if you just want to fake the data or fake the entire request. We recommend mocking the entire request as that is more likely to reflect a live production API.

Lastly we recommend putting your API specification inside of your version control. This enables your mock API to have different versions matching the corresponding changes in the source code.