Browse Source

Added api endpoint.

master
Silas Vedder 2 years ago
parent
commit
dd9e39861a
  1. 12
      api.lisp
  2. 2
      cl-bible.asd
  3. 7
      cl-bible.lisp
  4. 10
      package.lisp
  5. 2
      verse.lisp

12
api.lisp

@ -0,0 +1,12 @@
(in-package #:cl-bible.api)
(defvar *server* (make-instance 'h:easy-acceptor :port 4242))
(defmethod start ((server h:easy-acceptor))
(h:start server))
(h:define-easy-handler (get-reference :uri "/ref") (reference bible)
(setf (h:content-type*) "text/plain")
(setf (h:header-out :access-control-allow-origin) "*")
(let ((bible (d::read-bible-from-tsv (or bible "mng"))))
(j:to-json (v:to-sexp (s:find-verse bible (s:parse-position reference))))))

2
cl-bible.asd

@ -6,7 +6,7 @@
:license "MIT"
:version "0.0.4"
:serial t
:depends-on (#:str #:clog)
:depends-on (#:str #:clog #:hunchentoot #:jonathan)
:components ((:file "package")
(:file "chapter")
(:file "verse")

7
cl-bible.lisp

@ -12,8 +12,5 @@
(start)
(loop))
(defun build ()
(mapc (lambda (verse)
(setf (cl-bible.verse:notes verse) nil))
cl-bible.data:*bible*)
#+sbcl (sb-ext:save-lisp-and-die "bible" :executable t :toplevel #'main))
(defun build (&optional (name "bible"))
#+sbcl (sb-ext:save-lisp-and-die name :executable t :toplevel #'main))

10
package.lisp

@ -75,3 +75,13 @@
#:cl-bible.search)
(:local-nicknames (#:c #:clog)
(#:cg #:clog-gui)))
(defpackage #:cl-bible.api
(:use #:cl)
(:local-nicknames (#:l #:cl-bible.lift-search)
(#:d #:cl-bible.data)
(#:s #:cl-bible.search)
(#:v #:cl-bible.verse)
(#:ch #:cl-bible.chapter)
(#:h #:hunchentoot)
(#:j #:jonathan)))

2
verse.lisp

@ -33,7 +33,7 @@
(defgeneric from-sexp (bible))
(defmethod print-object ((verse verse) stream)
(format stream (verse-to-string verse :separator " ")))
(format stream (verse-to-string verse)))
(defmethod string-to-verse ((string string))
(let ((verse (uiop:split-string string :separator '(#\Tab))))

Loading…
Cancel
Save