On this page:
3.1 Available service documents

3 Macro

The simplest approach creates wrapper functions for the web service at compile time. This reduces startup time for your application. Furthermore, it means that you don’t need to ship the service documents—they are "source code" just like your .rkt files.

 (require (planet gh/gapi:1:=0/macro))


(require-gapi-doc discovery-document-name)

Defines functions respresenting the web service defined by the JSON file named discovery-document-name.

Each function makes an HTTP request to the web service. The function takes normal arguments for parameters that are defined as required, whereas optional keyword arguments are used to represent other parameters. These values are supplied in the HTTP request to the service.

The web service responds with JSON, which is returned by this function as a jsexpr?. This library doesn’t try to marshal the response into structs. Instead you will need to understand its format and retrieve the information, for example (hash-ref js 'items) if the response contains a list of items.

As a convenience, the #:key argument (which corresponds to the key query parameter in the HTTP request) defaults to the api-key Racket parameter. Put your Google API key in a file named .google-api-key in your home directory–in other words, ~/.google-api-key.

As another convenience, see the paged form which simplifies making repeated calls to a service that returns results in small "pages" (batches of results).

If discovery-document-name is a fully qualified pathname, then it will be loaded.

Otherwise if discovery-document-name has no path (i.e. if path-only returns #f) then it must be located in the vendor subdirectory of the GAPI collection. The currently available service documents are:

3.1 Available service documents


(require gapi/macro)
(require-gapi-doc "urlshortener.v1.js")
(define orig-url "http://www.racket-lang.org/")
(define js-insert (urlshortener-url-insert #:longUrl orig-url))
(define short-url (dict-ref js-insert 'id))
(define js-get (urlshortener-url-get short-url))
(define long-url (dict-ref js-get 'longUrl))
(printf "~s was shortened to ~s, which expanded back to ~s: ~a"
        orig-url short-url long-url
        (if (equal? orig-url long-url) "Yay!" "Boo!"))