scotty-rest-0.2.0.0: Webmachine-style REST library for scotty

Safe HaskellNone
LanguageHaskell2010

Web.Scotty.Rest

Contents

Synopsis

REST monad transformer

REST handler to Scotty

rest :: MonadIO m => RoutePattern -> Config m -> ScottyT RestException m () Source #

rest is used where you would use e.g. get in your Scotty app, and will match any method:

main = scotty 3000 $ do
  get  "/foo" (text "Hello!")
  rest "/bar" defaultConfig {
      contentTypesProvided = return [("text/html", html "Hello, World!")]
    }

Callback result types

data Authorized Source #

Response to isAuthorized callback.

Constructors

Authorized

User is authenticated and authorized.

NotAuthorized !Text

User is not authorized. The given challenge will be sent as part of the WWW-Authenticate header.

data DeleteResult Source #

Response to deleteResource callback.

Constructors

NotDeleted

The resource could not be deleted.

Deleted

The deletion operation has been fully completed.

DeletedWithResponse !MediaType !Text

The deletion operation has been fully completed. Respond with the given body.

DeleteEnacted

Accepted for processing, but the processing has not been completed (and may never be).

data ETag Source #

An ETag validator generated by the generateEtag callback.

Constructors

Strong Text

A strong ETag validator

Weak Text

A weak ETag validator

data Moved Source #

Result of the resourceMoved callback.

Constructors

NotMoved

Resource has not moved.

MovedTemporarily !Url

Resource has been temporarily moved to the given URL.

MovedPermanently !Url

Resource has been permanently moved to the given URL.

data ProcessingResult Source #

Result of a Processing request (e.g. POST, PUT, PATCH)

Constructors

Succeeded

Processing succeeded. Returns 204 No Content or 201 Created based on whether the resource existed previously or not.

SucceededWithContent !MediaType !Text

Processing succeeded with the given content. Returns 201 Created or 200 OK/300 Multiple Representations based on whether the resource existed previously or not.

SucceededWithLocation !Url

Processing succeeded with the given content. Returns 201 Created or 200 OK/300 Multiple Representations based on whether the resource existed previously or not.

Redirect !Url

Redirects (with 303 See Other) to the given URL.

Failed

Processing failed. Returns 400 Bad Request.

data Representation Source #

Response to multipleChoices callback.

Constructors

UniqueRepresentation

The resource has a unique representation.

MultipleRepresentations !MediaType !Text

There are multiple representations of this resource. Respond with the given body.

MultipleWithPreferred !MediaType !Text !Url

There are multiple representations of this resource, but one is preferred. Respond with the given body, and Url (in the Location header).

Config

data EndpointConfig m Source #

The callbacks that control a handler's behaviour. defaultConfig returns a config with default values. For typical handlers, you only need to override a few of these callbacks.

Constructors

EndpointConfig 

Fields

defaultConfig :: Monad m => Config m Source #

A RestConfig with default values. To override one or more fields, use record syntax:

defaultConfig {
  contentTypesProvided = return [("text/html", html "Hello, World!")]
}

Rest Exceptions

Re-exports

data StdMethod :: * #

HTTP standard method (as defined by RFC 2616, and PATCH which is defined by RFC 5789).

Constructors

GET 
POST 
HEAD 
PUT 
DELETE 
TRACE 
CONNECT 
OPTIONS 
PATCH 

data UTCTime :: * #

This is the simplest representation of UTC. It consists of the day number, and a time offset from midnight. Note that if a day has a leap second added to it, it will have 86401 seconds.

Instances

Eq UTCTime 

Methods

(==) :: UTCTime -> UTCTime -> Bool #

(/=) :: UTCTime -> UTCTime -> Bool #

Data UTCTime 

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> UTCTime -> c UTCTime #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c UTCTime #

toConstr :: UTCTime -> Constr #

dataTypeOf :: UTCTime -> DataType #

dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c UTCTime) #

dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c UTCTime) #

gmapT :: (forall b. Data b => b -> b) -> UTCTime -> UTCTime #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> UTCTime -> r #

gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> UTCTime -> r #

gmapQ :: (forall d. Data d => d -> u) -> UTCTime -> [u] #

gmapQi :: Int -> (forall d. Data d => d -> u) -> UTCTime -> u #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> UTCTime -> m UTCTime #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> UTCTime -> m UTCTime #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> UTCTime -> m UTCTime #

Ord UTCTime 
NFData UTCTime 

Methods

rnf :: UTCTime -> () #

ParseTime UTCTime 

Utilities

toHttpDateHeader :: UTCTime -> Text Source #

Formats a UTCTime as a HTTP date, e.g. Sun, 06 Nov 1994 08:49:37 GMT.

requestMethod :: Monad m => RestT m StdMethod Source #

Returns the method used for the current request, e.g. POST.