Sean Coughlin
Sean Coughlin's Blog


Sean Coughlin's Blog

Hosting an API with GitHub Pages

Photo by Douglas Lopes on Unsplash

Hosting an API with GitHub Pages

Hosting with GitHub Pages is an easy way to build a public JSON API

Sean Coughlin's photo
Sean Coughlin
·Jan 14, 2022·

2 min read

Play this article


GitHub Pages is a free website hosting tool provided by GitHub. I previously wrote about GitHub pages being an excellent place to host a personal website or project page. Additionally, it is a great choice to host a JSON API.

An API is a connection between computers. An example API would be the Spotify API which provides music data.


First, you will need to create a special [username] repository. This repository will be home to your GitHub Pages website. The repository name must exactly match the format [username], otherwise GitHub will not generate a live website.

Create a new GitHubPages Repo

I have already made a GitHub Pages repository so the name is taken for me. Your custom [username] will be available.

After creating [username] open the terminal, clone the repository, and cd into the directory.

git clone

Inside the repository you can create a .json file. That .json file will become your publicly accessible JSON API.

Example json file

After adding a .json file add, commit, and push your changes to GitHub.

git add .
git commit -m "Create JSON API"
git push -u origin master

Once you commit and push your changes to the codebase, GitHub will automatically build your changes and publish the code to the internet. It should only take a few minutes for the changes to become visible.

That's all it takes! You now have a JSON API for the world to see. Your new JSON API will be located at the URL [username][file-name].json. Your API can be seen using any web browser or an API testing tool like Postman.


GitHub Pages is a great tool for quickly creating a JSON API. In just a few minutes it's up and running!


  • The entire build process is automated and site changes are published to the internet within minutes.
  • GitHub Pages supports HTTPS to protect your site and users from malicious tampering.
  • Best of all, it's free!


Did you find this article valuable?

Support Sean Coughlin by becoming a sponsor. Any amount is appreciated!

See recent sponsors Learn more about Hashnode Sponsors
Share this