integral-rest

https://github.com/Rudolph-Miller/integral-rest.git

git clone 'https://github.com/Rudolph-Miller/integral-rest.git'

(ql:quickload :integral-rest)
2

Integral-Rest - REST APIs for Integral DAO Table.

Build Status

Usage

(defclass user ()
  ((id :initarg :id
       :primary-key t)
   (name :initarg :name))
  (:metaclass <dao-table-class>))

(set-rest-app)

(clack:clackup *rest-app*)

Installation

(ql:quickload :integral-rest)

API

set-rest-app

(defclass user ()
  ((id :initarg :id
       :primary-key t
       :accessor user-id)
   (name :initarg :name
         :accessor user-name))
  (:metaclass integral:<dao-table-class>))

(set-rest-app)
;; This sets REST API app to *rest-app*.

(defvar *my-rest-app* (set-rest-app))
;; (set-rest-app) also returns REST API app.

(set-rest-app (list (find-class 'user)))
;; (set-rest-app) can take list of class. (optional)
(defclass user ()
  ((id :initarg :id
       :primary-key t
       :accessor user-id)
   (name :initarg :name
         :accessor user-name))
  (:metaclass integral:<dao-table-class>))

(set-rest-app)

(clack:clackup *rest-app*)
;; => Listening on localhost:5000.

(create-dao 'user :name "Rudolph")
;; => #<USER id: 1>

(dex:get "http://localhost:5000/api/users")
;; => "[{\"id\":1,\"name\":\"Rudolph\"}]"

(dex:get "http://localhost:5000/api/users/1")
;; => "{\"id\":1,\"name\":\"Rudolph\"}"

(dex:post "http://localhost:5000/api/users" :contest '(("name" . "Miller")))
;; => "{\"id\":2,\"name\":\"Miller\"}"

(find-dao 'user 2)
;; => #<USER id: 2 name: "Miller">

(dex:put "http://localhost:5000/api/users/2" :contest '(("name" . "Tom")))
;; => "{\"id\":2,\"name\":\"Tom\"}"

(find-dao 'user 2)
;; => #<USER id: 2 name: "Tom">

(dex:delete "http://localhost:5000/api/users/2")
;; => "{\"id\":2,\"name\":\"Tom\"}"

(find-dao 'user 2)
;; => NIL

routing-rules

(defclass user ()
  ((id :initarg :id
       :primary-key t
       :accessor user-id)
   (name :initarg :name
         :accessor user-name))
  (:metaclass integral:<dao-table-class>))

(set-rest-app)

(routing-rules *rest-app*)
;; => '(("/api/users" :GET) ("/api/users" :POST) ("/api/users/:id" :GET)
;;      ("/api/users/:id" :PUT) ("/api/users/:id" :DELETE))

Author

See Also

Copyright

Copyright (c) 2015 Rudolph-Miller

License

Licensed under the MIT License.