REST API using Google Cloud Functions

Viewed 888

I have a general query regarding creating a simple REST API using Google Cloud Functions in Python. Is it best practice to create a HTTP function for each endpoint or create one function which handles all the endpoints?

Also is it possible to use a custom URL for the function e.g. /api/v1/pets/

2 Answers

I wrote 2 articles on that topic, one in Python and the other in Golang.

But I can't recommend you to do that for real world workload, it's fun when you hack but not more. You can have a look to my first article that explain why I prefer Cloud Run to Cloud Function, and the local testing is the main argument that I can offer. Then portability.

Google Cloud only supports one event definition per function. However, you could handle multiple definition by using same sources or use one trigger which has a response to call another function that combines different kind of events. You can refer to this GCP docs.

If you want to use a custom URL, you can check out Cloud Endpoints since it acts as an API Gateway for Cloud Functions.

Related