import: json: Accept '#:http-fetch' in 'json-fetch'.
authorPhilip McGrath <philip@philipmcgrath.com>
Wed, 18 May 2022 18:10:55 +0000 (14:10 -0400)
committerLudovic Courtès <ludo@gnu.org>
Sat, 21 May 2022 23:07:52 +0000 (01:07 +0200)
For example, supplying 'http-fetch/cached' would enable caching.

* guix/import/json.scm (json-fetch): Add '#:http-fetch' argument.

Signed-off-by: Ludovic Courtès <ludo@gnu.org>
guix/import/json.scm

index 0c98bb2..ae00ee9 100644 (file)
             json->scheme-file))
 
 (define* (json-fetch url
+                     #:key
+                     (http-fetch http-fetch)
                      ;; Note: many websites returns 403 if we omit a
                      ;; 'User-Agent' header.
-                     #:key (headers `((user-agent . "GNU Guile")
-                                      (Accept . "application/json"))))
+                     (headers `((user-agent . "GNU Guile")
+                                (Accept . "application/json"))))
   "Return a representation of the JSON resource URL (a list or hash table), or
 #f if URL returns 403 or 404.  HEADERS is a list of HTTP headers to pass in
-the query."
+the query.  HTTP-FETCH is called to perform the request: for example, to
+enable caching, supply 'http-fetch/cached'."
   (guard (c ((and (http-get-error? c)
                   (let ((error (http-get-error-code c)))
                     (or (= 403 error)