1
0
Fork 0

Compare commits

...

3 Commits

Author SHA1 Message Date
Craig Oates 8c87cf5b37 fix typo in .gitignore (.directory) 3 years ago
Craig Oates 09dd5f9b6e add functions and comments for making HTTP-Requests. 3 years ago
Craig Oates e912fdc73d add drakma and cl-json packages to project. 3 years ago
  1. 2
      .gitignore
  2. 2
      ritherdon-rest.asd
  3. 5
      src/package.lisp
  4. 35
      src/ritherdon-rest.lisp

2
.gitignore vendored

@ -17,4 +17,4 @@
*.wx64fsl
*.wx32fsl
/.directory
*.directory

2
ritherdon-rest.asd

@ -8,6 +8,7 @@
:version "0.0.1"
:serial t
:in-order-to ((test-op (test-op "ritherdon-rest/tests")))
:depends-on (:drakma :cl-json)
:pathname "src/"
:components ((:file "package")
(:file "ritherdon-rest")))
@ -19,7 +20,6 @@
:author "craig@craigoates.net"
:license "MIT"
:version "0.0.1"
:serial t
:depends-on (:ritherdon-rest :fiveam)
:perform (test-op (o s)
(uiop:symbol-call :fiveam :run!

5
src/package.lisp

@ -1,4 +1,7 @@
;;;; package.lisp
(defpackage #:ritherdon-rest
(:use #:cl))
(:use #:cl #:drakma :cl-json)
(:export :parse-request
:decode-json)) ; Part of cl-json, getting errors without
; it in SLIME.

35
src/ritherdon-rest.lisp

@ -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)))