Building an API With GCP

Muhammed Arshid K
3 min readNov 7, 2020

In this post, I will build an API with Google cloud platform. I’ll build the back end with Google Cloud Function and Python.

The Basics

To start, I wanted to go over some basic concepts about what APIs are and how the technologies work. This is completely introductory, so feel free to skip this section if you are already familiar.

API stands for Application Programming Interface and refers to the method that computer systems use to communicate with one another.

Google’s dictionary defines APIs as:

“A set of functions and procedures allowing the creation of applications that access the features or data of an operating system, application, or other service.”

You build out an API so your system can communicate with whatever you’re building. APIs can include basic REST endpoints for a website or even the methods that define a software library you’ve built.

Which brings up the next important thing, RESTful services.

RESTful services refer to Representational State Transfer and take advantage of the HTTP protocol to pass data (via an API). The HTTP protocol is what we use every day in websites and internet applications.

RESTful services use different HTTP verbs (or methods) to pass data between different systems.

Typical HTTP verbs include:

  • GET = retrieving data
  • POST = creating or updating data
  • PUT = updating data
  • DELETE = deleting data

I also mentioned endpoints earlier; that’s what I’ll refer to when I mention a website or service I need to hit. An endpoint is just a fancy way to describe an address that my system will hit with an HTTP request.

Setup

You need a google cloud account.

1.Navigation Bar → cloud function

2. create new function

where you give a function name and region. then you can use triggering method. here , I used HTTP method ,and choose an Authentication method. if you create a public API or website choose “Allow unauthenticated invocations” then press save button . In advanced option you can set Memory allocated, Environment Variables ..etc

click next

3. Deploy

In GCP cloud function you can use different programming languages such as Node.js ,GO, Java, python. Here, I used Python. in Source code section you will see 2 files one is main.py file and requrement.txt file.

after writing your code press deploy function

after deploying the function you can see the green tick mark then you can test the function in test in console otherwise postman.

happy coding ,start with GCP

--

--

Muhammed Arshid K

AI & ML Enthusiast | APJ Abdul Kalam Technological University ,Kerala |B Tech Final year Student at LBS College of Engineering Kasaragod.