webapi

2021-06-30

CLOS-based wrapper builder for Web APIs

Upstream URL

github.com/fukamachi/webapi

Author

Eitaro Fukamachi

License

BSD 2-Clause

README.md

WebAPI

CLOS-based wrapper builder for Web APIs.

Usage

(ql:quickload '(:webapi :jonathan))

;; Define GitHub API request class.
(defclass github-request () ()
  (:default-initargs :base-uri "https://api.github.com"))
  
(defmethod webapi:parse ((request github-request) response)
  (jojo:parse (webapi:response-body response) :as :alist))

;; Request class for /users/:name/repos.
(defclass user-repositories (github-request)
  ((user :initarg :user))
  (:metaclass webapi:request-class)
  (:http :get))
  
(defmethod webapi:request-path ((request user-repositories))
  (format nil "/users/~A/repos" (slot-value request 'user)))

;; Request class for /search/repositories.
(defclass search-repositories (github-request)
  ((q :initarg :q))
  (:metaclass webapi:request-class)
  (:http :get "/search/repositories"))
  
(defmethod webapi:query-parameters ((request search-repositories))
  `(("q" . ,(slot-value request 'q))))
  
;;
;; Send a request

;; Get repositories of "fukamachi".
(webapi:send (make-instance 'user-repositories :user "fukamachi"))

;; Search repositories with related to "Common Lisp".
(webapi:send (make-instance 'search-repositories :q "Common Lisp"))

Author

Copyright

Copyright (c) 2017 Eitaro Fukamachi (e.arrows@gmail.com)

License

Licensed under the BSD 2-Clause License.

Dependencies (6)

  • alexandria
  • closer-mop
  • dexador
  • kebab
  • quri
  • st-json

Dependents (0)

    • GitHub
    • Quicklisp
    • Sponsor