0 | module HTTP.API.Server
 1 |
 2 | import public HTTP.API
 3 | import public HTTP.API.Server.Content
 4 | import public HTTP.API.Server.Env
 5 | import public HTTP.API.Server.Header
 6 | import public HTTP.API.Server.Interface
 7 | import public HTTP.API.Server.Method
 8 | import public HTTP.API.Server.Path
 9 | import public HTTP.API.Server.Query
10 | import public HTTP.Prog
11 | import public HTTP.Request
12 | import public HTTP.Response
13 |
14 | %default total
15 |
16 | public export
17 | data Server : Endpoints -> Type where
18 |   Nil  : Server []
19 |   (::) :
20 |        {0 ts       : List Type}
21 |     -> {0 as       : Endpoints}
22 |     -> {endpoint   : HList ts}
23 |     -> {auto all   : All Serve ts}
24 |     -> {auto con   : HList (Constraints endpoint)}
25 |     -> EndpointHandler endpoint
26 |     -> Server as
27 |     -> Server (endpoint :: as)
28 |
29 | public export
30 | (++) : Server es -> Server fs -> Server (es ++ fs)
31 | (++) []      sfs = sfs
32 | (++) (s::ss) sfs = s :: (ss ++ sfs)
33 |
34 | export
35 | serveAll :
36 |      (0 endpoints : Endpoints)
37 |   -> Server endpoints
38 |   -> Request
39 |   -> Handler Response
40 | serveAll [] [] req = throw (requestErr notFound404)
41 | serveAll (endpoint :: as) ((::) {endpoint} f x) req =
42 |   case canServe endpoint req of
43 |     True  => serveEndpoint endpoint f req
44 |     False => serveAll as x req
45 |