Module
QuickServe
- Package
- purescript-quickserve
- Repository
- paf31/purescript-quickserve
#Servable Source
class Servable server where
A type class for types of values which define servers.
Servers are built from the Method
data type, which
defines the method, record types which define routes
and function types which make things like the request
body and query parameters available.
Members
Instances
(IsSymbol method, IsResponse response) => Servable (Method method response)
(IsRequest request, Servable service) => Servable (RequestBody request -> service)
(Servable service) => Servable (Capture -> service)
(RowToList r l, ServableList l r) => Servable (Record r)
#IsResponse Source
class IsResponse response where
A type class for response data.
Members
encodeResponse :: response -> String
responseType :: Proxy response -> String
Instances
IsResponse String
(Encode a) => IsResponse (JSON a)
#Method Source
#RequestBody Source
newtype RequestBody a
RequestBody
can be used to read the request body.
To read the request body, use a function type with a function
argument type which has an IsRequest
instance:
main = quickServe opts echo where
echo :: RequestBody String -> GET String
echo (RequestBody s) = pure s
Constructors
Instances
Newtype (RequestBody a) _
(IsRequest request, Servable service) => Servable (RequestBody request -> service)
#Capture Source
newtype Capture
Capture
can be used to capture a part of the route.
Use a function type with a function
argument of type Capture
:
main = quickServe opts echo' where
echo' :: Capture -> GET String
echo' (Capture s) = pure s
Constructors
Instances
#quickServe Source
quickServe :: forall server. Servable server => ListenOptions -> server -> Effect Unit
Start a web server given some Servable
type
and an implementation of that type.
For example:
opts = { hostname: "localhost"
, port: 3000
, backlog: Nothing
}
main = quickServe opts hello where
hello :: GET String
hello = pure "Hello, World!""
#ServableList Source
class ServableList (l :: RowList) (r :: Row Type) | l -> r where
Members
Instances
ServableList Nil ()
(IsSymbol route, Servable s, ServableList l r1, Cons route s r1 r) => ServableList (Cons route s l) r
- Modules
- QuickServe