REST API using Google Cloud Functions - google-cloud-functions

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/

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

Can I see the complete request URL (including the query string) for Google Cloud Function requests?

I'm using Google Cloud Functions and requests contain a query string https://europe-west1-foobar.cloudfunctions.net/foobar?bar=baq
Is it possible for me to retrieve bar=baq from the Google Cloud logs? If so, how?
For the moment there's no such feature - just as guillaume blaquiere wrote.
However you can file a feature request on IssueTracker. Provide as much detailes on how you'd like this feature to work, maybe some examples - that will improve the chance of it being implemented.

Why are some Google Sheets API v4 functions not documented?

I'm trying to understand how the Google Sheet API v4 works, so I check the sample codes provided by Google for the API methods. When looking at the examples for Google Apps Script (e.g. batchUpdate), I find this method, Sheets.newUpdateSpreadsheetPropertiesRequest(), and many more - all beginning with the prefix new. I've searched, but I can't find these methods described anywhere in the documentation.
This is for me not as clear as the behavior of the Spreadsheet Service (SpreadsheetApp).
Have I missed something, or is the REST API not well-documented?
The Advanced Service APIs are wrappers for their corresponding REST APIs. Methods prefixed with new are constructors for the corresponding resource object in the respective API (used mainly for auto-completion).
For example Sheets.newUpdateSpreadsheetPropertiesRequest() is equivalent to the UpdateSpreadsheetPropertiesRequest object. It takes a bit of getting used to, but spend some time navigating the documentation. It will begin to make sense eventually.

Testing Google Compute API within a sandbox

Is there any way to test Google Compute Engine API calls within a sandboxed environment for development/testing purposes? For example, to invoke an API call to create instances without having to create (and then pay for) actual instances.
Thanks

Is it possible to use google maps without using a callback?

I'd like to have google maps loop through a bunch of cities while doing a nearby search. However, the asynchronous strategy from maps is not allowing the code to operate as intended. I want it to be procedural and it seems like removing the callback would fix it.
Does anyone have advise?
Generally the answer has to be NO
The Maps-API internally uses a lot of async-requests, for example the loading of the tiles is the result of the callback of an asynchronous request.
But the issue here are not asynchronous requests at all, it's asynchronous requests to services(geocoding, places).
When I redefine the question to :
Is it possible to use responses of google maps services without using a callback?
The answer has to be: YES
These webservices may be accessed from serverside too, so you may get the results on serverside and pass them to the scripts directly.
Another option would be a synchronous request to the webservices, but in practice this would block the browser until you get the response, that's not a desirable option.

When using the Google Places API, what is the difference between "using the JavaScript library" and "calling the API directly"?

I have seen the two forms of reference to the Google Places Library/Service, using JavaScript vs calling the API directly, a number of times, but I don't understand the difference. The Google Docs don't describe anything about two methods of accessing the API.
For example, this question talks about 2 ways of accessing the API: OVER_QUERY_LIMIT in a loop
And it appears that there is some type of direct web access taking place in this question: Querying Google Places API using jQuery
Is this something where there was an old way that involved formatting URL parameters and the new way is by utilizing the JavaScript library calls?
FINAL SUMMARY EDIT: There are two distinct ways of requesting data from Google, as described in #Dan Nissenbaum's answer below. And since my original question, the QUERY_LIMIT question referenced above has been edited to also include more information about the two options.
Perhaps you are referring to the distinction between the Google Places API that is intended for use on the SERVER (i.e., utilizing PHP to call the Google Places API directly), and using the completely different approach of the Google Places Javascript Library in which the BROWSER executes Javascript using the Javascript library provided by Google (that internally wraps calls to the Google Places API, so that you, as a Javascript programmer, only need to understand the Javascript library provided by Google, and use that)?
Here are the two scenarios.
Scenario #1: Use the API directly. For this method, you must refer to Google's API documentation for the Google Places API: https://developers.google.com/maps/documentation/places/.
Using this API works as follows (giving a simple example only). Say you want to retrieve places within 1000 meters of latitude=-27.2531166, longitude=138.8655664. You need to hit a URL as described by the API documentation: https://developers.google.com/maps/documentation/places/#PlaceSearchRequests.
In this example, the URL looks like this (it's long):
https://maps.googleapis.com/maps/api/place/search/json?location=-27.2531166,138.8655664&radius=1000&sensor=false&key=AddYourOwnKeyHere
You need a key for your personal use, which I assume you have. There are other options you can specify, such as limiting the results to restaurants, etc.
When you hit this URL, the data will be returned in either JSON, or XML format, as specified by the text json in the URL above (use the text xml for xml). This data is returned exactly like data is returned from any URL call when you hit a URL in your browser.
You can test this by simply typing the URL directly in your browser, and see the results.
To use the API directly from code, you will need to use code that hits the external URL above within code and retrieves the results within code (for example, using the PHP CURL library, or using AJAX in Javascript).
Scenario #2: You use the Javascript library that Google provides that wraps the API, so you don't need to deal with it. I'll update the answer with more details about this, if you don't know what this is.
The docs do discuss the two different approaches. The Places Library utilizes the Google Places services from within the JavaScript Google Maps API. If you are using the Google Maps API in a browser, this is probably the approach for you:
https://developers.google.com/maps/documentation/javascript/places
There is also a web service, which allows you to query directly from your application. You query it using direct http calls to Google services. If you need access to the data on your server or a mobile device, this is the approach you want to take:
https://developers.google.com/maps/documentation/places