Greg Slepak avatar Greg Slepak committed 1489bf2

updated some stuff on the routes page

Comments (0)

Files changed (1)


 		<h1>Default Routes</h1>
 		<p class="extract">
+			Dragonfly's routes are written in pure newLISP code and have no arbitrary constraints placed on them. They can be as simple or complex as you need them to be. In fact, Dragonfly's routes are so flexible that the defaults will often be all you'll need.
 		<h2>Static Routes</h2>
 		<p>Static Routes in Dragonfly provide two behaviours:</p>
 		<p class="info">The resource <b>WINGS</b> has to be available in Your resource directory</p>
 		<h3 class="code">Example of wings.lsp in /resources</h3>
 		<pre class="code">
-;; @author Greg Slepak
 (DF:activate-plugin "artfulcode/json")
+(new Resource 'Resource.Wings)
 (context 'Resource.Wings)
 (set 'my-data
-	'((wings (left right))
-	(wings-condition ("good" "excellent"))
-	(wings-opacity 0.5))
+  '((wings (left right))
+    (wings-condition ("good" "excellent"))
+    (wings-opacity 0.5))
-(define (Resource.Wings:Resource.Wings response-format)
-	; defaults to calling show
-	(show response-format)
+(define (Resource.Wings:Resource.Wings id response-format)
+    ; defaults to calling show
+    (show id response-format)
-(define (show response-format)
-	(if (= response-format "json")
-		(begin
-			(Response:content-type Response:json-type)
-			(print (Json:lisp->json my-data))
-		)
-		(begin
-			(Response:content-type Response:text-type)
-			(print my-data)
-		)
-	)
+(define (show id response-format)
+    ; in this situation we can't use newLISP's default
+    ; parameter values to do this for us.
+    (if-not id (set 'id 0))
+    ; uh-oh! No range checking on 'resource-id' ...
+    (if (= response-format "json")
+        (begin
+            (Response:content-type Response:json-type)
+            (print (Json:lisp->json (my-data id)))
+        )
+        (begin
+            (Response:content-type Response:text-type)
+            (print (my-data id))
+        )
+    )
-(context MAIN)			
-		</pre>
+(context MAIN)</pre>
 		<p class="config"><b>Configuration</b><br/>You may enable or disable RESTful handling by setting the constant ENABLE_RESTFUL_HANDLER in config.lsp. Default is set to "true".</p>
 		<p class="config"><b>Configuration</b><br/>Set Your resource directory to whatever You want by changing the constant RESOURCES_PATH in config.lsp. Default is set to "/resources".</p>	
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.