diff options
-rw-r--r-- | README.org | 5 | ||||
-rw-r--r-- | src/client/ps/generate.lisp | 13 |
2 files changed, 13 insertions, 5 deletions
@@ -67,8 +67,9 @@ OOPyness is an advantage. Object orientation allows one to: endponit classes. Whole regions of a site or API can easly be extended or modified. -- You can use the reified endpoints to automatically for your - API. See the function ~weekend:print-all-route-documentation~. +- You can use the reified endpoints to automatically generate + documentation for your API. See the function + ~weekend:print-all-route-documentation~. - Similarly, you can automatically generate API client code for your langauge of choice. diff --git a/src/client/ps/generate.lisp b/src/client/ps/generate.lisp index 63c7753..0b1b458 100644 --- a/src/client/ps/generate.lisp +++ b/src/client/ps/generate.lisp @@ -10,7 +10,7 @@ ;; this function largely mirrors the implementation of construct-route-builder -(defun generate (class &optional alt-name) +(defun generate (class &key alt-name (content-type "application/json")) (when (symbolp class) (setf class (find-class class))) (let* @@ -53,14 +53,21 @@ method ,(string method) cache "no-cache" ,@(when (wknd:body-expected-p method) - `(headers (ps:create "Content-Type" "application/json"))) + `(headers (ps:create "Content-Type" ,content-type))) redirect "follow" ,@(when body (list 'body body)))) (then (lambda (resp) (and resp (= 200 (ps:@ resp status)) - (ps:chain resp (json))))))))) + ,(cond ((string= content-type "application/json") + `(ps:chain resp (json))) + + ((string= content-type "text/" :end1 5) + `(ps:chain resp (text))) + + (t + `(ps:chain resp (blob))))))))))) |