34 lines
		
	
	
	
		
			1.2 KiB
		
	
	
	
		
			Common Lisp
		
	
	
	
	
	
			
		
		
	
	
			34 lines
		
	
	
	
		
			1.2 KiB
		
	
	
	
		
			Common Lisp
		
	
	
	
	
	
;;;; cl-scopes/web/client - web client functionality
 | 
						|
 | 
						|
(defpackage :scopes/web/client
 | 
						|
  (:use :common-lisp)
 | 
						|
  (:local-nicknames (:config :scopes/config)
 | 
						|
                    (:core :scopes/core)
 | 
						|
                    (:message :scopes/core/message))
 | 
						|
  (:export #:config #:base-url #:api-path #:doc-path
 | 
						|
           #:get-page #:send-message))
 | 
						|
 | 
						|
(in-package :scopes/web/client)
 | 
						|
 | 
						|
(defclass config (config:base)
 | 
						|
  ((config:setup :initform #'core:default-setup)
 | 
						|
   (base-url :reader base-url :initarg :base-url :initform "http://localhost:8135")
 | 
						|
   (doc-path :reader doc-path :initarg :doc-path :initform "/")
 | 
						|
   (api-path :reader api-path :initarg :api-path :initform "/api/")))
 | 
						|
 | 
						|
;;;; client context (= service)
 | 
						|
 | 
						|
(defun get-page (ctx msg)
 | 
						|
  (let* ((cfg (core:config ctx))
 | 
						|
         (path (getf (message:data msg) :path))
 | 
						|
         (url (str:concat (base-url cfg) (doc-path cfg) path)))
 | 
						|
    (dex:get url)))
 | 
						|
 | 
						|
(defun send-message (ctx msg)
 | 
						|
  (let* ((cfg (core:config ctx))
 | 
						|
         (url (str:concat (base-url cfg) (api-path cfg) (msgpath msg))))
 | 
						|
    (dex:get url)))
 | 
						|
 | 
						|
(defun msgpath (msg)
 | 
						|
  (let ((lst (loop for p in (message:head-as-list msg) when p collect p)))
 | 
						|
    (str:join "/" (mapcar #'string-downcase lst))))
 |