QuickServe
- Package
- purescript-quickserve
- Repository
- paf31/purescript-quickserve
#Servable Source
class Servable eff server | server -> eff 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 eff (Method method eff response)
(IsRequest request, Servable eff service) => Servable eff (RequestBody request -> service)
(Servable eff service) => Servable eff (Capture -> service)
(RowToList r l, ServableList eff l r) => Servable eff (Record r)
#quickServe Source
quickServe :: forall server eff. Servable (console :: CONSOLE | eff) server => ListenOptions -> server -> Eff (console :: CONSOLE, http :: HTTP | eff) 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!""
#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
newtype Method (m :: Symbol) eff response
A Servable
type constructor which indicates the expected
method (GET, POST, PUT, etc.) using a type-level string.
Constructors
Instances
Newtype (Method m eff response) _
Functor (Method m eff)
Apply (Method m eff)
Applicative (Method m eff)
Bind (Method m eff)
Monad (Method m eff)
MonadEff (http :: HTTP | eff) (Method m eff)
MonadAff (http :: HTTP | eff) (Method m eff)
(IsSymbol method, IsResponse response) => Servable eff (Method method eff response)
#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 eff service) => Servable eff (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
#ServableList Source
class ServableList eff (l :: RowList) (r :: Row Type) | l -> r where
Members
serveListWith :: LProxy l -> Record r -> Request -> Response -> List String -> Maybe (Eff (http :: HTTP | eff) Unit)
Instances
ServableList eff Nil ()
(IsSymbol route, Servable eff s, ServableList eff l r1, RowCons route s r1 r) => ServableList eff (Cons route s l) r
- Modules
- QuickServe
- QuickServe.
Internal