This blog is very related to my previous blog related to the use of Google Spreadsheet as "CMS". You can read it first to understand the previous context first before going further.
The idea came from my current hobby by the way. I usually go to some cosplay or Japanese Cultural events around the Jabodetabek area. I got the general event list that provided by the cosplay communities. But because it's only a Google Spreadsheet, I think it's not user-friendly and readable for some people. That's why I think it's better to create a public AI that gets the data from it, so everyone can create the web based on it too.
Here's some highlight process that I've been going through to create the Japanese Culture Event List API.
I used Express JS in this mini-project. I create the base project structure by using these commands.
is for loading the env vars. is the JS backend library that I use for this project. And is the official Google client library for Node.js. The dev deps that I use are Typescript related because I'm using Typescript here.
Here's my content.
Don't forget to setup the also if using Typescript.
Then, I created the folder and in there.
Like common APIs that are made using Express JS, here's my code declaration. I'll use the variable that using the Google Sheet API to collect the data.
I create two endpoints here. The first endpoint is which get all the event list from the Google Sheet. It also can be filtered by the city name.
The second endpoint is which return the list of cities. I use JS to make it unique for each cities.
In the end, here's my snippet to make sure the server run well in my local device and do the module export.
To run and test it in the local device, just run . It will run in . It will return the base list data.
Want to see my full source code? You can access it here. For deployment purposes, I used Vercel. If you want to use Vercel too to deploy your API, you can follow the guide here.
For the documentation purpose, I used Postman because I'm familiar with it😅. Here's a quick guide to creating API Documentation using Postman.
Make sure you already have the Postman Desktop App and create an account when you open it for the first time. On the tab click the button to create a new collection.
To simplify the process, you can select the template that has been provided to you. For me, I choose the template as a starter template.
After that, you can make changes to the project description based on your needs.
If you're ready to publish your own API Docs, you can click the button on the top right menu. You can read the full steps in the Postman Official Documentation.
This is just a simple example of the Google Sheet API usage. As I've told you in the previous article, this seems trivial but actually, this kind of tool can be utilized for many things for our needs as a software engineer. You can use Google Sheet API as a "CMS" or even like in this article, you can create REST API through Google Sheet API.
I hope this article can help you when you have to deliver a web app with a tight deadline, you can use this as a reference.