|
|
|
@ -1,6 +1,37 @@
|
|
|
|
|
;;;; ritherdon-rest.lisp |
|
|
|
|
|
|
|
|
|
;;; A collection of functions to aid in the make |
|
|
|
|
;;; http-requests to the Ritherdon REST API. This project is help me |
|
|
|
|
;;; learn Common Lisp. So, there is not much emphasis on being too |
|
|
|
|
;;; strict on best practices and defensive coding. |
|
|
|
|
|
|
|
|
|
;;; NOTE: The Ritherdon REST API is part of an art exhibition at time |
|
|
|
|
;;; of writing (29/06/2021). You will need to check if the server is |
|
|
|
|
;;; still running if you want to run this code. |
|
|
|
|
|
|
|
|
|
(in-package #:ritherdon-rest) |
|
|
|
|
|
|
|
|
|
(defun hello () |
|
|
|
|
(print "The system is up and running.")) |
|
|
|
|
;; All the data provided by the Ritherdon REST API is in JSON. Becuase |
|
|
|
|
;; of this I can set the `TEXT-CONTENT-TYPE' to JSON and keep it like |
|
|
|
|
;; that until further notice. |
|
|
|
|
(setq drakma:*text-content-types* (cons '("application" . "json") |
|
|
|
|
drakma:*text-content-types*)) |
|
|
|
|
|
|
|
|
|
;; The Base URL which you build all your HTTP Requests on. You will |
|
|
|
|
;; need to refer back to http://ritherdon.abbether.net/api/ui/ for the |
|
|
|
|
;; full set of URL's. |
|
|
|
|
(defvar *base-url* "http://ritherdon.abbether.net/api") |
|
|
|
|
|
|
|
|
|
;; The http-request is actually 'drakma:http-request'. I've done it |
|
|
|
|
;; this way to highlight the feature. It is the same as what you've |
|
|
|
|
;; used in the past with C# and 'using static' statements. So, not |
|
|
|
|
;; much to go into here apart from highlighting it's a thing in Common |
|
|
|
|
;; Lisp, too. |
|
|
|
|
(defun make-request (query) |
|
|
|
|
(http-request (concatenate 'string *base-url* query))) |
|
|
|
|
|
|
|
|
|
;; Same as the drakma example above. It can read as |
|
|
|
|
;; 'cl-json:decode-json-from-string' but omitted the 'cl-json' |
|
|
|
|
;; bit. You will find all package declarations in /src/package.lisp'. |
|
|
|
|
(defun parse-request (query) |
|
|
|
|
(decode-json-from-string(make-request query))) |
|
|
|
|