summaryrefslogtreecommitdiff
path: root/Router.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Router.hs')
-rw-r--r--Router.hs21
1 files changed, 21 insertions, 0 deletions
diff --git a/Router.hs b/Router.hs
new file mode 100644
index 0000000..4798ec1
--- /dev/null
+++ b/Router.hs
@@ -0,0 +1,21 @@
+module Router where
+
+import Control.Exception
+import Response
+import Request
+
+data Route = Route (Request -> IO Response) String String
+
+data RouterError = RouteNotFound
+ deriving Show
+
+instance Exception RouterError
+
+getResponse [] _ = throw RouteNotFound
+getResponse (Route callback routeUrl _ : routerTable) req @ (Request _ url _) =
+ if url == routeUrl then
+ callback req
+ else getResponse routerTable req
+
+router table req =
+