Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor http verbs into their own file #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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