Fake JSON API Server with JSONPlaceHolder

Saidel López
3 min readApr 29, 2019

JSONPlaceHolder is a great solution to integrate an instant JSON server with your Github repositories. Let me tell you my experience.

A while ago, in an older post — TIL: Api Mock Responses in Mobile development — I checked different ways to store a fake JSON content so I can implement a mobile app whether or not a real production server is available. Even one of my possible solutions was to store the JSON file as GIST post and retrieve it with the proper URL to the content.

All about integration

JSONPlaceHolder is a free online API Server you can use to integrate regular API responses to your application. It also has feature I’ve been using for while. You can read JSON responses that you already have in a server at Github through this API. This way you can make changes in your JSON files in your Github repository (including branches) and always keep on reading your fake data.

The instructions are very simple. Just by creating a file called db.json in the root of your Github repository will make the trick. You can access you JSON file through the URL https://my-json-server.typicode.com/user/repo where user is your Github user and repo is the name if the Github repo (should be public)

My own test

In my repository Flashcards I created the proper db.json file. https://github.com/saishaddai/Flashcards/blob/master/db.json

Now, going directly to the URL https://my-json-server.typicode.com/saishaddai/Flashcards/ I found it actually knows how many objects there are there to show

There’s also a URL to access each one of the objects and the whole list of objects in there.

Limitations

It worked for me since my file is only a small number of attributes and fields. I learned it has a limitation of 5 fields to show so no pagination is allowed. Also, I found that this is an alpha version so some times there’s an internal server error. Needles to say, I really big file won’t be rightly processed and might be difficult to know if there’s a server error retrieving your objects or if you made an error writing your JSON file.

Conclusion

This is a good first step to a good integration and version tracking of your implementations. It has a lot of limitations but the idea is great if it can be improved. I was able to share my JSON to anyone and show different versions of it with two branches which is also a good thing you can use right now.

To know more

The JSONPlaceholder site with some JSON examples you can actually read from them. https://jsonplaceholder.typicode.com/

Also, the instructions to properly set your JSON as a real server https://my-json-server.typicode.com/

--

--