Skip to content

Commit

Permalink
Refactor http verbs into their own file
Browse files Browse the repository at this point in the history
  - Add patch verb
  - Add some documentation in docstrings. A definition of content-verb
  is missing.
  • Loading branch information
PuercoPop committed Jan 20, 2016
1 parent d2d0122 commit 46e08a8
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 22 deletions.
27 changes: 5 additions & 22 deletions common.lisp
Original file line number Diff line number Diff line change
@@ -1,27 +1,10 @@
(in-package #:snooze-common)


;;; Verbs
;;;
;;; "Sending" and "Receiving" are always from the server's
;;; perspective. Hence GET is "sending to client" and POST and PUT are
;;; "receiving from client".
;;;
(defpackage :snooze-verbs (:use) (:export #:http-verb #:get #:post #:put #:delete
#:content-verb
#:receiving-verb
#:sending-verb))

(cl:defclass snooze-verbs:http-verb () ())
(cl:defclass snooze-verbs:delete (snooze-verbs:http-verb) ())
(cl:defclass snooze-verbs:content-verb (snooze-verbs:http-verb) ())
(cl:defclass snooze-verbs:receiving-verb (snooze-verbs:content-verb) ())
(cl:defclass snooze-verbs:sending-verb (snooze-verbs:content-verb) ())
(cl:defclass snooze-verbs:post (snooze-verbs:receiving-verb) ())
(cl:defclass snooze-verbs:put (snooze-verbs:receiving-verb) ())
(cl:defclass snooze-verbs:get (snooze-verbs:sending-verb) ())

(defun destructive-p (verb) (typep verb 'snooze-verbs:receiving-verb))

(defun destructive-p (verb)
"Returns true if it is possible for a request with the http VERB to modify
the server state."
(typep verb 'snooze-verbs:receiving-verb))


;;; Content-types
Expand Down
26 changes: 26 additions & 0 deletions http.lisp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
;;; HTTP Verbs

(defpackage #:snooze-verbs
(:use)
(:export #:http-verb
#:get
#:patch
#:post
#:put
#:delete
#:content-verb
#:receiving-verb
#:sending-verb)
(:documentation "The taxonomy of HTTP verbs used by snooze. In addition to the verbs themselves it groups verbs in content, sending and receiving verbs. Sending and Receiving are always from the server's perspective. Hence GET is sending to client and POST and PUT are receiving from client."))

(cl:defclass snooze-verbs:http-verb () ())
(cl:defclass snooze-verbs:delete (snooze-verbs:http-verb) ())
(cl:defclass snooze-verbs:content-verb (snooze-verbs:http-verb) ())
(cl:defclass snooze-verbs:receiving-verb (snooze-verbs:content-verb) ()
(:documentation "Indicates that the request carries information from the client to the server."))
(cl:defclass snooze-verbs:sending-verb (snooze-verbs:content-verb) ()
(:documentation "Indicates that the request is asking information from the server."))
(cl:defclass snooze-verbs:patch (snooze-verbs:receiving-verb) ())
(cl:defclass snooze-verbs:post (snooze-verbs:receiving-verb) ())
(cl:defclass snooze-verbs:put (snooze-verbs:receiving-verb) ())
(cl:defclass snooze-verbs:get (snooze-verbs:sending-verb) ())
1 change: 1 addition & 0 deletions snooze.asd
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
:components ((:file "package")
(:file "constants")
(:file "safe-simple-read")
(:file "http")
(:file "common")
(:file "api")))

Expand Down

0 comments on commit 46e08a8

Please sign in to comment.