diff options
author | David Thompson <dthompson2@worcester.edu> | 2015-01-30 23:49:13 -0500 |
---|---|---|
committer | David Thompson <dthompson2@worcester.edu> | 2015-01-30 23:49:13 -0500 |
commit | 8f00bede78e2585426a16e8160a40970c4c89e3c (patch) | |
tree | ed0003f28adbce5afcdf99067949032e05dc748a | |
parent | 604bc9f2cf810115d4053004ea2cb3c4775d9722 (diff) |
Make /package a JSON only route.
* guix-web/controller.scm (extract-package-name): New procedure.
(controller): Only render JSON for '/package' routes.
-rw-r--r-- | guix-web/controller.scm | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/guix-web/controller.scm b/guix-web/controller.scm index b3104fe..fa7dfc3 100644 --- a/guix-web/controller.scm +++ b/guix-web/controller.scm @@ -17,7 +17,9 @@ (define-module (guix-web controller) #:use-module (ice-9 match) + #:use-module (ice-9 regex) #:use-module (srfi srfi-1) + #:use-module (srfi srfi-26) #:use-module (web request) #:use-module (gnu packages) #:use-module (guix-web render) @@ -26,6 +28,12 @@ #:use-module (guix-web package) #:export (controller)) +(define extract-package-name + (let ((regexp (make-regexp "^(.*)\\.json$"))) + (lambda (path-part) + (and=> (regexp-exec regexp path-part) + (cut match:substring <> 1))))) + (define controller (match-lambda ((GET) @@ -34,15 +42,8 @@ (render-html (all-packages))) ((GET "packages.json") (render-json (all-packages-json))) - ((GET "packages" name) - (match (string-split name #\.) - ((name ext) - (render-json - (if (string=? ext "json") - (view-package-json name) - '()))) - ((name) - (render-html (view-package name))))) + ((GET "package" (= extract-package-name (? string? name))) + (render-json (view-package-json name))) ((POST "packages" name "install") (let ((package (car (find-packages-by-name name)))) (if (package-install package) |