]> gitweb.factorcode.org Git - factor.git/commitdiff
Support PUT and PATCH requests
authorBenjamin Pollack <benjamin@bitquabit.com>
Sat, 15 Sep 2018 19:39:51 +0000 (15:39 -0400)
committerJohn Benediktsson <mrjbq7@gmail.com>
Sun, 16 Sep 2018 15:34:25 +0000 (08:34 -0700)
Resolves #1431

basis/furnace/actions/actions-docs.factor
basis/furnace/actions/actions.factor

index 88bacd2c04634e753d004812a44687c5c559fa9a..af5cac082ac2b45e26738008835d65e09131d73f 100644 (file)
@@ -99,6 +99,8 @@ ARTICLE: "furnace.actions.config" "Furnace action configuration"
     { { $slot "display" } { "A quotation called after the " { $slot "init" } " quotation in a GET request. This quotation must return an HTTP " { $link response } "." } }
     { { $slot "validate" } { "A quotation called at the beginning of a POST request to validate POST parameters." } }
     { { $slot "submit" } { "A quotation called after the " { $slot "validate" } " quotation in a POST request. This quotation must return an HTTP " { $link response } "." } }
+    { { $slot "replace" } { "A quotation called after the " { $slot "validate" } " quotation in a PUT request. This quotation must return an HTTP " { $link response } "." } }
+    { { $slot "update" } { "A quotation called after the " { $slot "validate" } " quotation in a PATCH request. This quotation must return an HTTP " { $link response } "." } }
 }
 "At least one of the " { $slot "display" } " and " { $slot "submit" } " slots must be set, otherwise the action will be useless." ;
 
index 4d3a179942299b1f71735423ca467073abeadb71..cdf088ee535ac07648d04c2a3359f8e3f876bf1b 100644 (file)
@@ -19,7 +19,7 @@ IN: furnace.actions
 
 SYMBOL: rest
 
-TUPLE: action rest init authorize display validate submit ;
+TUPLE: action rest init authorize display validate submit update replace ;
 
 : new-action ( class -- action )
     new [ ] >>init [ ] >>validate [ ] >>authorize ; inline
@@ -83,6 +83,26 @@ CONSTANT: revalidate-url-key "__u"
         ] [ drop <400> ] if
     ] with-exit-continuation ;
 
+: handle-put ( action -- response )
+    '[
+        _ dup submit>> [
+            [ validate>> call( -- ) ]
+            [ authorize>> call( -- ) ]
+            [ replace>> call( -- response ) ]
+            tri
+        ] [ drop <400> ] if
+    ] with-exit-continuation ;
+
+: handle-patch ( action -- response )
+    '[
+        _ dup submit>> [
+            [ validate>> call( -- ) ]
+            [ authorize>> call( -- ) ]
+            [ update>> call( -- response ) ]
+            tri
+        ] [ drop <400> ] if
+    ] with-exit-continuation ;
+
 : handle-rest ( path action -- )
     rest>> [ [ "/" join ] dip set-param ] [ drop ] if* ;
 
@@ -93,9 +113,11 @@ CONSTANT: revalidate-url-key "__u"
 M: action call-responder* ( path action -- response )
     [ init-action ] keep
     request get method>> {
-        { "GET" [ handle-get ] }
-        { "HEAD" [ handle-get ] }
-        { "POST" [ handle-post ] }
+        { "GET"   [ handle-get ] }
+        { "HEAD"  [ handle-get ] }
+        { "POST"  [ handle-post ] }
+        { "PUT"   [ handle-put ] }
+        { "PATCH" [ handle-patch ] }
         [ 2drop <405> ]
     } case ;