</ Amal>

</ Amal>

Fake API - An API to generate fake data

Fake API - An API to generate fake data

Here is an API for all the frontend developers. An API to generate fake data, lots of it. This tool comes in handy when you are developing a frontend for applications that requires data a lot of data.

Frontend frameworks like React, Vue, etc., are trendy, and many applications are built on these frameworks. Hot reloading is one of the features of such libraries. So when you press save, the whole app reloads, and all the APIs are called.

Making multiple API calls every few seconds is a costly task. Keeping the backend running the whole time to prototype the frontend is also an expensive process. This is where an API generating fake data comes into play.


How does the API work?

The API is built using FastAPI, and the fake data is generated using the Faker library. All the data types(the type of data generated) supported by the API are the ones in Faker.


  • [GET] /api/types

    This endpoint returns all the data types supported. Only these types should be provided as values to any key.

  • [POST] /api/

    This endpoint does all the heavy lifting. It generates fake data based on the JSON payload. Each key in the payload is an identifier, i.e., the key in the resulting fake data. The value to each key must be one of the valid data types. For an invalid type, the API ignores the entry.

For example,

    "name": "name"

Will generate something like,

    "name": "Amal Shaji"

What kind of payload can the API handle?

  • Simple Payloads


  • Complex payloads (nested JSON)


  • Complex payloads (Maybe the person has multiple contact information)


You can use the repeat key for repeating any block of data. Max repeat count is 10. Use the repeat key in the outer block to get data for n users.

The function to generate data based on the payload is recursive. So whenever the function encounters a dict, it calls itself, solving all the nested structures. interesting.PNG

Hmm. Interesting...

Navigate to fakeapi.tk/api/types to know about all the supported data types. Fire up your favorite API testing client and test it out with various data types.

Happy Hunting🥳🥳

Share this