scotty
Haskell web framework inspired by Ruby's Sinatra, using WAI and Warp
https://github.com/scotty-web/scotty
Version on this page: | 0.11.0@rev:5 |
LTS Haskell 22.43: | 0.20.1@rev:1 |
Stackage Nightly 2024-12-05: | 0.22@rev:2 |
Latest on Hackage: | 0.22@rev:2 |
scotty-0.11.0@sha256:ae76edc7f78a68ecf982aaa2d4421e80796a365fbb13c38b1cf0f77c3586e482,4393
Module documentation for 0.11.0
- Web
- Web.Scotty
- Web.Scotty.Internal
- Web.Scotty.Trans
- Web.Scotty
Scotty
A Haskell web framework inspired by Ruby’s Sinatra, using WAI and Warp.
{-# LANGUAGE OverloadedStrings #-}
import Web.Scotty
import Data.Monoid (mconcat)
main = scotty 3000 $ do
get "/:word" $ do
beam <- param "word"
html $ mconcat ["<h1>Scotty, ", beam, " me up!</h1>"]
Scotty is the cheap and cheerful way to write RESTful, declarative web applications.
- A page is as simple as defining the verb, url pattern, and Text content.
- It is template-language agnostic. Anything that returns a Text value will do.
- Conforms to WAI Application interface.
- Uses very fast Warp webserver by default.
See examples/basic.hs to see Scotty in action. (basic.hs needs the wai-extra package)
> runghc examples/basic.hs
Setting phasers to stun... (port 3000) (ctrl-c to quit)
(visit localhost:3000/somepath)
As for the name: Sinatra + Warp = Scotty.
More Information
Tutorials and related projects can be found in the Scotty wiki:
https://github.com/scotty-web/scotty/wiki
Development & Support
Open an issue on GitHub or join #scotty
on Freenode.
Copyright (c) 2012-2014 Andrew Farmer
Changes
0.11.0
- IO exceptions are no longer automatically turned into ScottyErrors by
liftIO
. UseliftAndCatchIO
to get that behavior. - New
finish
function. - Text values are now leniently decoded from ByteStrings.
- Added
MonadFail
instance forScottyT
- Lots of bound bumps on dependencies.
0.10.2
- Removed debug statement from routes
0.10.1
Parsable
instances forWord
,Word8
,Word16
,Word32
,Word64
[adamflott]Parsable
instances forInt8
,Int16
,Int32
,Int64
, andNatural
- Removed redundant
Monad
constraint onmiddleware
0.10.0
-
The monad parameters to
ScottyT
have been decoupled, causing the type of theScottyT
constructor to change. As a result,ScottyT
is no longer aMonadTrans
instance, and the type signatures ofscottyT
,scottyAppT
, andscottyOptsT
have been simplified. [ehamberg] -
socketDescription
no longer uses the deprecatedPortNum
constructor. Instead, it uses theShow
instance forPortNumber
. This changes the bytes from host to network order, so the output ofsocketDescription
could change. [ehamberg] -
Alternative
,MonadPlus
instances forActionT
-
scotty
now depends ontransformers-compat
. As a result,ActionT
now usesExceptT
, regardless of which version oftransformers
is used. As a result, several functions inWeb.Scotty.Trans
no longer require aScottyError
constraint, sinceExceptT
does not require anError
constraint (unlikeErrorT
). -
Added support for OPTIONS routes via the
options
function [alvare] -
Add
scottySocket
andscottySocketT
, exposing Warp Unix socket support [hakujin] -
Parsable
instance for lazyByteString
[tattsun] -
Added streaming uploads via the
bodyReader
function, which retrieves chunks of the request body. [edofic]ActionEnv
had agetBodyChunk
field added (inWeb.Scotty.Internal.Types
)RequestBodyState
andBodyPartiallyStreamed
added toWeb.Scotty.Internal.Types
-
jsonData
usesaeson
’seitherDecode
instead of justdecode
[k-bx]
0.9.1
- text/html/json only set Content-Type header when not already set
0.9.0
-
Add
charset=utf-8
toContent-Type
fortext
,html
andjson
-
Assume HTTP status 500 for
defaultHandler
-
Remove deprecated
source
method. -
No longer depend on conduit.
0.8.2
-
Bump
aeson
upper bound -
Fix
mtl
related deprecation warnings
0.8.1
-
Export internal types
-
Added
MonadBase
,MonadTransControl
andMonadBaseControl
instances forActionT
0.8.0
-
Upgrade to wai/wai-extra/warp 3.0
-
No longer depend on conduit-extra.
-
The
source
response method has been deprecated in favor of a newstream
response, matching changes in WAI 3.0. -
Removed the deprecated
reqHeader
function.
0.7.3
- Bump upper bound for case-insensitive, mtl and transformers.
0.7.2
- Bump lower bound on conduit, add conduit-extra to cabal build depends.
0.7.1
- Default warp settings now use
setFdCacheDuration 0
to work around a warp issue where file changes are not getting picked up.
0.7.0
-
Renamed
reqHeader
toheader
. Addedheaders
function to get all headers. -
Changed
MonadIO
instance forActionT
such that IO exceptions are lifted intoScottyError
s viastringError
. -
Make
Bool
parsing case-insensitive. Goal: support both Haskell’s True/False and Javascript’s true/false. Thanks to Ben Gamari for suggesting this. -
Bump
aeson
/text
upper bounds. -
Bump
wai
/wai-extra
/warp
bounds, including new lower bound forwarp
, which fixes a security issue related to Slowloris protection.
0.6.2
- Bump upper bound for
text
.
0.6.1
- Match changes in
wai-extra
.
0.6.0
-
The Scotty transformers (
ScottyT
andActionT
) are now parameterized over a custom exception type, allowing one to extend Scotty’sErrorT
layer with something richer thanText
errors. See theexceptions
example for use.ScottyM
andActionM
remain specialized toText
exceptions for simplicity. -
Both monads are now instances of
Functor
andApplicative
. -
There is a new
cookies
example. -
Internals brought up-to-date with WAI 2.0 and related packages.
0.5.0
-
The Scotty monads (
ScottyM
andActionM
) are now monad transformers, allowing Scotty applications to be embedded in arbitraryMonadIO
s. The old API continues to be exported fromWeb.Scotty
where:type ScottyM = ScottyT IO type ActionM = ActionT IO
The new transformers are found in
Web.Scotty.Trans
. See theglobalstate
example for use. Special thanks to Dan Frumin (co-dan) for much of the legwork here. -
Added support for HTTP PATCH method.
-
Removed lambda action syntax. This will return when we have a better story for typesafe routes.
-
reqHeader :: Text -> ActionM Text
==>reqHeader :: Text -> ActionM (Maybe Text)
-
New
raw
method to set body to a rawByteString
-
Parse error thrown by
jsonData
now includes the body it couldn’t parse. -
header
split intosetHeader
andaddHeader
. The former replaces a response header (original behavior). The latter adds a header (useful for multipleSet-Cookie
s, for instance).