diff options
| author | Andrew Guschin <saintruler@gmail.com> | 2020-11-26 13:55:55 +0400 |
|---|---|---|
| committer | Andrew Guschin <saintruler@gmail.com> | 2020-11-26 13:55:55 +0400 |
| commit | 446602fe336ad1c2a23e3d50d7cd1d1356fcc9de (patch) | |
| tree | 74b8a1ca93c17d22f7876f6aba80ee10c3851d3b /Router.hs | |
Initial commit
Diffstat (limited to 'Router.hs')
| -rw-r--r-- | Router.hs | 21 |
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 = + |