moonshine-1.2.2.1: A web service framework for Haskell, similar in purpose to dropwizard.

Safe HaskellNone
LanguageHaskell2010

Web.Moonshine

Synopsis

Documentation

data LoggingConfig Source

Logging configuration that Moonshine should use to initialize logging.

This type is an instance of FromJSON, so you can easily use it in your configuration as:

 data MyConfig = MyConfig {
   logging :: LoggingConfig
 } deriving (Generic)
 instance FromJSON MyConfig
 

Constructors

LoggingConfig 

Fields

level :: LogPriority
 
logfile :: Maybe FilePath
 
loggers :: [LoggerDetails]
 

runMoonshine :: Moonshine a -> IO a Source

Execute an insance of the Moonshine monad. This starts up a server and never returns.

route :: [(ByteString, Moonshine ())] -> Moonshine () Source

Like route, but that automatically sets up metrics for the specified routes.

makeTimer :: Text -> Moonshine Timer Source

Make a new timer with the given name.

timerAdd :: (Real time, MonadIO io) => Timer -> time -> io () Source

Add a time to a timer.

data Timer Source

The Timer type.

getUserConfig :: (MonadIO io, FromJSON config) => io config Source

Returns the user config.

timed Source

Arguments

:: Text

The name of the timer.

-> Moonshine a

The action to be wrapped.

-> Moonshine a 

Wrap a Moonshine in a timer, so that timing data for invocations will be logged to the metrics handler.

liftSnap :: Snap () -> Moonshine () Source

Lifts a snap action into a moonshine action.

liftIO :: MonadIO m => forall a. IO a -> m a

Lift a computation from the IO monad.

badRequest :: String -> Snap a Source

Using this will short-circuit the snap monad (in much the same way as fail does for all monads), but instead the regular meaning of "fail" in the snap monad (which allows the framework to choose some other path), this short-circuit causes a 400 Bad Request to be returned no matter what.

requiredParam :: ByteString -> Snap ByteString Source

Look up a parameter, and if it doesn't exist, then cause a 400 BadRequest to be returned to the user

requiredUtf8Param :: ByteString -> Snap Text Source

Look up a parameter, and decode it using utf8. If the parameter doesn't exist, then cause a 400 BadReqeust to be returned to the user.

writeJSON :: ToJSON json => json -> Snap () Source

Write a ToJSON instance to the entity body, setting the Content-Type header to application/json.

setBanner :: String -> IO () Source

Sets the banner that moonshine should display on startup.

readJSON :: FromJSON json => Int64 -> Snap json Source

Read a FromJSON from the request entity, causing a 400 bad request on a parsing error. The first argument specifies the maximum size we are willing to read. This method delegates to readRequestBody, so an exception will be thrown in the case where the maximum size is exceeded.

created :: Snap () Source

Return a 201 Created response.

noContent :: Snap () Source

Return a 204 No Content response.

methodNotAllowed :: [Method] -> Snap a Source

Short circuit with a 405 Method Not Allowed. Also, set the Allow header with the allowed methods.

assertMethod :: Method -> Snap a -> Snap a Source

Asserts that the request was made using a particular HTTP request method. If the assertion fails, then the request will result in a 405 Method Not Allowed.

timedIO :: MonadIO io => Timer -> io a -> io a Source

Time how long it takes to perform some kind of IO. This function is compatible with any MonadIO.

makeGauge :: Text -> Moonshine Gauge Source

Create a new gauge with the given name.

gaugeInc :: MonadIO io => Gauge -> io () Source

Add one to a gauge value.

gaugeDec :: MonadIO io => Gauge -> io () Source

Subtract one from a gauge value.

gaugeSet :: MonadIO io => Gauge -> Int64 -> io () Source

Set the gauge the a specific value one from a gauge value.

gaugeAdd :: MonadIO io => Gauge -> Int64 -> io () Source

Add a value to a gauge.

gaugeSubtract :: MonadIO io => Gauge -> Int64 -> io () Source

Subtrace a value from a gauge.

data Gauge Source

The Gauge type.

notFound :: Snap a Source

Short circuit with a 404 Not Found.

setServerVersion Source

Arguments

:: String

name - The name of your server.

-> Version

version - The version of your server.

-> Moonshine () 

Utility method that sets the Server: header to something sensible.

class ResponseEntity e where Source

The class of things that can be used as http response entities.

Methods

getContentType :: e -> ContentType Source

The content type of the respone entity.

getBytes :: e -> ByteString Source

The bytes associated with the response entity.

writeEntity :: ResponseEntity e => e -> Snap () Source

A more powerful version of writeJSON. This function writes generic ResponseEntitys, and sets the right content type for them.

getMethod :: Snap Method Source

Shorthand Snap action for retrieving the request method.

conflict :: Snap () Source

Set the reponse code to 409 Conflict.

type ContentType = ByteString Source

ContentType is an alias for ByteString

class RequestEntity e where Source

The class of things that can be read as request entitys.

Methods

decodeEntity :: Maybe ContentType -> ByteString -> DecodeResult e Source

Decode the entity, according to the specified content type.

data DecodeResult e Source

The result of trying to decode a request entity.

Constructors

Unsupported

Signifies an unsupported content type.

BadEntity String

Signifies that the request entity is invalid, and provides some kind of reason why.

Ok e

Successfully decoded the entity.

readEntity :: RequestEntity e => Int64 -> Snap e Source

Reads and decodes a request entity, returning the appropriate error responses if the entity can't be decoded: 415 Unsupported Media Type if the content type is not supported, or 400 Bad Request if the content type is supported, but the entity can't be decoded.

unsupportedMediaType :: Snap a Source

Short circuit with a 415 response.

exactPath :: Snap a -> Snap a Source

Make sure that the path info is empty. If it isn't, then fail the snap action using pass. This is helpful when using routes to make sure that a route named "foo" does not match an request uri of "foo/bar"