From 446602fe336ad1c2a23e3d50d7cd1d1356fcc9de Mon Sep 17 00:00:00 2001 From: Andrew Guschin Date: Thu, 26 Nov 2020 13:55:55 +0400 Subject: Initial commit --- Router.hs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Router.hs (limited to 'Router.hs') 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 = + -- cgit v1.2.3