45 lines
1.5 KiB
Text
45 lines
1.5 KiB
Text
;; This an Artanis ENTRY file, don't remove it!
|
|
|
|
(use-modules (artanis artanis)
|
|
;; Put modules you want to be imported here
|
|
;; only for this file, not controllers/views
|
|
|
|
(artanis utils))
|
|
|
|
(use-modules (srfi srfi-71)
|
|
(artanis artanis)
|
|
(web uri)
|
|
(web client)
|
|
(web request))
|
|
|
|
|
|
|
|
;; Put whatever you want to be called before server initilization here
|
|
|
|
(init-server #:statics '(png gif jpg jpeg ico html js json csv xml css woff woff2 ttf))
|
|
(add-to-load-path (string-append (current-toplevel) "/lib"))
|
|
;; Put whatever you want to be called before server running here
|
|
|
|
(get "/"
|
|
(lambda ()
|
|
(let* ((uri
|
|
(string->uri
|
|
(string-append
|
|
;; No HTTPS because Guile/Guile GnuTLS doesn't
|
|
;; support TLS handshakes on a non blocking socket
|
|
;; yet
|
|
"http://data.guix.gnu.org"
|
|
"/revision/e5478c6acf74c3d5b1d25125baac23171403bd1d"
|
|
"/packages.json?locale=en_US.UTF-8&field=version&field=synopsis&limit_results=100")))
|
|
(socket
|
|
(open-socket-for-uri uri)))
|
|
|
|
;; If you comment out the following line, this example will work
|
|
(fcntl socket F_SETFL (logior O_NONBLOCK (fcntl socket F_GETFL)))
|
|
|
|
(let ((response
|
|
body
|
|
(http-get uri
|
|
#:port socket
|
|
#:streaming? #t)))
|
|
(simple-format #f "~A" (json->scm body))))))
|