8

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 2

7

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Guillaume, good reads. I was looking for examples in the Google documentation and didn't find my specific use case.
3

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.

1 Comment

Great thank you. I will check it out.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.