Skip to content

Commit

Permalink
release 0.21 (#362)
Browse files Browse the repository at this point in the history
* haddock
  • Loading branch information
ocramz authored Dec 17, 2023
1 parent e036cbc commit cb0e4c9
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 28 deletions.
21 changes: 16 additions & 5 deletions Web/Scotty.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@ module Web.Scotty
, middleware, get, post, put, delete, patch, options, addroute, matchAny, notFound, nested, setMaxRequestBodySize
-- ** Route Patterns
, capture, regex, function, literal
-- ** Accessing the Request, Captures, and Query Parameters
-- ** Accessing the Request and its fields
, request, header, headers, body, bodyReader
, jsonData, files
-- ** Accessing Path, Form and Query Parameters
, param, params
, pathParam, captureParam, formParam, queryParam
, pathParamMaybe, captureParamMaybe, formParamMaybe, queryParamMaybe
, pathParams, captureParams, formParams, queryParams
, jsonData, files
-- ** Modifying the Response and Redirecting
, status, addHeader, setHeader, redirect
-- ** Setting Response Body
Expand Down Expand Up @@ -267,6 +268,8 @@ param = Trans.param . toStrict
{-# DEPRECATED param "(#204) Not a good idea to treat all parameters identically. Use pathParam, formParam and queryParam instead. "#-}

-- | Synonym for 'pathParam'
--
-- /Since: 0.20/
captureParam :: Trans.Parsable a => Text -> ActionM a
captureParam = Trans.captureParam . toStrict

Expand Down Expand Up @@ -306,27 +309,29 @@ queryParam = Trans.queryParam . toStrict
-- NB : Doesn't throw exceptions. In particular, route pattern matching will not continue, so developers
-- must 'raiseStatus' or 'throw' to signal something went wrong.
--
-- /Since: FIXME/
-- /Since: 0.21/
pathParamMaybe :: (Trans.Parsable a) => Text -> ActionM (Maybe a)
pathParamMaybe = Trans.pathParamMaybe . toStrict

-- | Synonym for 'pathParamMaybe'
--
-- /Since: 0.21/
captureParamMaybe :: (Trans.Parsable a) => Text -> ActionM (Maybe a)
captureParamMaybe = Trans.pathParamMaybe . toStrict

-- | Look up a form parameter. Returns 'Nothing' if the parameter is not found or cannot be parsed at the right type.
--
-- NB : Doesn't throw exceptions, so developers must 'raiseStatus' or 'throw' to signal something went wrong.
--
-- /Since: FIXME/
-- /Since: 0.21/
formParamMaybe :: (Trans.Parsable a) => Text -> ActionM (Maybe a)
formParamMaybe = Trans.formParamMaybe . toStrict

-- | Look up a query parameter. Returns 'Nothing' if the parameter is not found or cannot be parsed at the right type.
--
-- NB : Doesn't throw exceptions, so developers must 'raiseStatus' or 'throw' to signal something went wrong.
--
-- /Since: FIXME/
-- /Since: 0.21/
queryParamMaybe :: (Trans.Parsable a) => Text -> ActionM (Maybe a)
queryParamMaybe = Trans.queryParamMaybe . toStrict

Expand Down Expand Up @@ -398,12 +403,18 @@ raw = Trans.raw


-- | Access the HTTP 'Status' of the Response
--
-- /Since: 0.21/
getResponseStatus :: ActionM Status
getResponseStatus = Trans.getResponseStatus
-- | Access the HTTP headers of the Response
--
-- /Since: 0.21/
getResponseHeaders :: ActionM ResponseHeaders
getResponseHeaders = Trans.getResponseHeaders
-- | Access the content of the Response
--
-- /Since: 0.21/
getResponseContent :: ActionM Content
getResponseContent = Trans.getResponseContent

Expand Down
16 changes: 11 additions & 5 deletions Web/Scotty/Action.hs
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ queryParam = paramWith QueryParameterNotFound envQueryParams
-- NB : Doesn't throw exceptions. In particular, route pattern matching will not continue, so developers
-- must 'raiseStatus' or 'throw' to signal something went wrong.
--
-- /Since: FIXME/
-- /Since: 0.21/
pathParamMaybe :: (Parsable a, Monad m) => T.Text -> ActionT m (Maybe a)
pathParamMaybe = paramWithMaybe envPathParams

Expand All @@ -367,23 +367,23 @@ pathParamMaybe = paramWithMaybe envPathParams
-- NB : Doesn't throw exceptions. In particular, route pattern matching will not continue, so developers
-- must 'raiseStatus' or 'throw' to signal something went wrong.
--
-- /Since: FIXME/
-- /Since: 0.21/
captureParamMaybe :: (Parsable a, Monad m) => T.Text -> ActionT m (Maybe a)
captureParamMaybe = paramWithMaybe envPathParams

-- | Look up a form parameter. Returns 'Nothing' if the parameter is not found or cannot be parsed at the right type.
--
-- NB : Doesn't throw exceptions, so developers must 'raiseStatus' or 'throw' to signal something went wrong.
--
-- /Since: FIXME/
-- /Since: 0.21/
formParamMaybe :: (Parsable a, Monad m) => T.Text -> ActionT m (Maybe a)
formParamMaybe = paramWithMaybe envFormParams

-- | Look up a query parameter. Returns 'Nothing' if the parameter is not found or cannot be parsed at the right type.
--
-- NB : Doesn't throw exceptions, so developers must 'raiseStatus' or 'throw' to signal something went wrong.
--
-- /Since: FIXME/
-- /Since: 0.21/
queryParamMaybe :: (Parsable a, Monad m) => T.Text -> ActionT m (Maybe a)
queryParamMaybe = paramWithMaybe envQueryParams

Expand Down Expand Up @@ -428,7 +428,7 @@ paramWithMaybe f k = do
params :: Monad m => ActionT m [Param]
params = paramsWith getParams
{-# DEPRECATED params "(#204) Not a good idea to treat all parameters identically. Use pathParams, formParams and queryParams instead. "#-}

-- | Get path parameters
pathParams :: Monad m => ActionT m [Param]
pathParams = paramsWith envPathParams
Expand All @@ -455,12 +455,18 @@ getParams e = envPathParams e <> envFormParams e <> envQueryParams e
-- === access the fields of the Response being constructed

-- | Access the HTTP 'Status' of the Response
--
-- /SINCE 0.21/
getResponseStatus :: (MonadIO m) => ActionT m Status
getResponseStatus = srStatus <$> getResponseAction
-- | Access the HTTP headers of the Response
--
-- /SINCE 0.21/
getResponseHeaders :: (MonadIO m) => ActionT m ResponseHeaders
getResponseHeaders = srHeaders <$> getResponseAction
-- | Access the content of the Response
--
-- /SINCE 0.21/
getResponseContent :: (MonadIO m) => ActionT m Content
getResponseContent = srContent <$> getResponseAction

Expand Down
5 changes: 3 additions & 2 deletions Web/Scotty/Trans.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ module Web.Scotty.Trans
, middleware, get, post, put, delete, patch, options, addroute, matchAny, notFound, setMaxRequestBodySize
-- ** Route Patterns
, capture, regex, function, literal
-- ** Accessing the Request, Captures, and Query Parameters
-- ** Accessing the Request and its fields
, request, Lazy.header, Lazy.headers, body, bodyReader
, jsonData, files
-- ** Accessing Path, Form and Query Parameters
, param, params
, pathParam, captureParam, formParam, queryParam
, pathParamMaybe, captureParamMaybe, formParamMaybe, queryParamMaybe
, pathParams, captureParams, formParams, queryParams
, jsonData, files
-- ** Modifying the Response and Redirecting
, status, Lazy.addHeader, Lazy.setHeader, Lazy.redirect
-- ** Setting Response Body
Expand Down
1 change: 1 addition & 0 deletions Web/Scotty/Util.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE LambdaCase #-}
{-# options_ghc -Wno-unused-imports #-}
module Web.Scotty.Util
( lazyTextToStrictByteString
, strictByteStringToLazyText
Expand Down
19 changes: 14 additions & 5 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
## next [????.??.??]

* add getResponseHeaders, getResponseStatus, getResponseContent (#214)

## 0.21 [2023.12.17]
### New
* add `getResponseHeaders`, `getResponseStatus`, `getResponseContent` (#214)
* add `captureParamMaybe`, `formParamMaybe`, `queryParamMaybe` (#322)
* deprecate `rescue` and `liftAndCatchIO` (#332)
* add `Web.Scotty.Trans.Strict` and `Web.Scotty.Trans.Lazy` (#334)
* Reverted the `MonadReader` instance of `ActionT` so that it inherits the base monad (#342)
* renamed `captureParam`, `captureParamMaybe`, and `captureParams` to `pathParam`, `pathParamMaybe`, `pathParams` respectively, keeping the old names as their synonyms (#344)

### Deprecated
* deprecate `rescue` and `liftAndCatchIO` (#332)
* Deprecate `StatusError`, `raise` and `raiseStatus` (#351)

### Fixes
* Reverted the `MonadReader` instance of `ActionT` so that it inherits the base monad (#342)
* Scotty's API such as `queryParam` now throws `ScottyException` rather than `StatusException`.
Uncaught exceptions are handled by `scottyExceptionHandler`, resembling the existing behaviour
* Deprecate `StatusError`, `raise` and `raiseStatus` (#351)

### Documentation
* Add doctest, refactor some inline examples into doctests (#353)
* document "`defaultHandler` only applies to endpoints defined after it" (#237)

## 0.20.1 [2023.10.03]

## 0.20.1 [2023.10.03]
* remove dependencies on 'base-compat' and 'base-compat-batteries' (#318)
* re-add MonadFail (ActionT m) instance (#325)
* re-add MonadError (ActionT m) instance, but the error type is now specialized to 'StatusError' (#325)
Expand Down
2 changes: 1 addition & 1 deletion scotty.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Name: scotty
Version: 0.20.1
Version: 0.21
Synopsis: Haskell web framework inspired by Ruby's Sinatra, using WAI and Warp
Homepage: https://github.com/scotty-web/scotty
Bug-reports: https://github.com/scotty-web/scotty/issues
Expand Down
20 changes: 10 additions & 10 deletions test/Web/ScottySpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,16 @@ spec = do
request "POST" "/" [("Content-Type","multipart/form-data; boundary=--33")]
large `shouldRespondWith` 200

describe "middleware" $ do
context "can rewrite the query string (#348)" $ do
withApp (do
Scotty.middleware $ \app req sendResponse ->
app req{queryString = [("query", Just "haskell")]} sendResponse
Scotty.matchAny "/search" $ queryParam "query" >>= text
) $ do
it "returns query parameter with given name" $ do
get "/search" `shouldRespondWith` "haskell"


describe "ActionM" $ do
context "MonadBaseControl instance" $ do
Expand Down Expand Up @@ -178,16 +188,6 @@ spec = do
it "Responds with a 302 Redirect" $ do
get "/a" `shouldRespondWith` 302 { matchHeaders = ["Location" <:> "/b"] }

describe "middleware" $ do
context "rewrites the query string" $ do
withApp (do
Scotty.middleware $ \app req sendResponse ->
app req{queryString = [("query", Just "haskell")]} sendResponse
Scotty.matchAny "/search" $ queryParam "query" >>= text
) $ do
it "returns query parameter with given name" $ do
get "/search" `shouldRespondWith` "haskell"

describe "captureParam" $ do
withApp (
do
Expand Down

0 comments on commit cb0e4c9

Please sign in to comment.