Create a FREE 🎉 Fake REST API with JSON Server Running On The Internet

Animesh Roy
3 min readApr 21, 2020

In this article, I will show you how to create a fake REST API using JSON Server FOR FREE… 🙌

I was working on a simple Android application that retrieves some JSON data(using GET request) & displays in the UI. The issue is that: REST URL endpoint was not responding because the URL expired. Then I found that creating a fully-fledged REST API has lots of things involved. From registering a domain to setting up a server, connecting to a database. Creating a REST API using ExpressJS/NodeJS/DjangoREST framework takes time.

I just want to interact with a simple JSON data (eg: like this). Then why should I spend too much creating a fully-fledged REST API from scratch just to retrieve some simple JSON data? Right…

Here comes JSON Server Typicode(GitHub) to rescue and save our energy/time. 🕒

With just simple steps you can host an URL Endpoint for JSON data on the internet. You can use GET, POST, PUT, PATCH and DELETE requests.

Here is what I created: https://my-json-server.typicode.com/animeshroydev/SampleJSONPlaceholder

IF YOU PREFER WATCHING VIDEO 🎥 OVER READING ARTICLE. I HAVE ALSO CREATED A YOUTUBE VIDEO ON IT AS WELL.

Step 1:

Create a folder with any name you want. I named it FakeJSONPlaceholder. I suggest you follow along with me. Then open your favorite code editor (I use VS Code) and open the folder in Editor you just created. The folder is empty now. If you are using VS Code open terminal (View > Integrated Terminal). If you are using another code editor open Terminal/Command Prompt and cd into the folder.

Make sure that you have Node.JS installed in your machine. If it isn’t there, just download it.

Step 2:

Write command in terminal/command prompt:

npm init

Now it will ask to provide some info. Just ignore and hit enter for everything.

Step 3:

Now we have a package.json file inside the folder.

Time to Install the JSON server now. Write to the terminal:

npm install --save json-server

It will take some time to install. Once it installed you can see some other files/code added to your folder.

Step 4:

Create a new file & name it db.json

Put the JSON data you want to retrieve in your apps. I am pasting this data in db.json

Step 5:

In package.json replace the existing value of key name: “scripts” to:

"scripts": {"json:server": "json-server --watch db.json"},

Step 6:

Time to run the server. Write the command:

npm run json:server

The server should start on http://localhost:3000

Open http://localhost:3000 in your browser. It will display a nice page with the parent JSON key exactly like this. Click on the resources(users, companies, contacts) you will see JSON data associated with each parent keys.

SO FAR SO GOOD 😇

Now time to host the server on the internet for FREE. For that, you need to create a new repository in GitHub and Pushed the local repo to remote GitHub.

After you pushed the local repo to origin master. Open the URL:

https://my-json-server.typicode.com/<your-github-username>/<your-repo-name>

My URL: https://my-json-server.typicode.com/animeshroydev/SampleJSONPlaceholder

👊 AWESOME WORK. YOU JUST CREATED A SIMPLE FAKE REST API WITH FEW STEPS. NOW USE THE ENDPOINT URL AS BACKEND TO YOUR SAMPLE APPS TO RETRIEVE THEM.

--

--