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

#IsResponse Source

class IsResponse response  where

A type class for response data.

Members

Instances

#IsRequest Source

class IsRequest request  where

A type class for request data.

Members

Instances

#JSON Source

newtype JSON a

A request/response type which uses JSON as its data representation.

Constructors

Instances

#Method Source

newtype Method (m :: Symbol) response

A Servable type constructor which indicates the expected method (GET, POST, PUT, etc.) using a type-level string.

Constructors

Instances

#GET Source

type GET = Method "GET"

A resource which responds to GET requests.

#POST Source

type POST = Method "POST"

A resource which responds to POST requests.

#PUT Source

type PUT = Method "PUT"

A resource which responds to PUT requests.

#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

#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 :: # Type) | l -> r where

Members

Instances

Modules
QuickServe