scotty

Scotty

Scotty lightweight web framework patterns for simple Haskell HTTP services built on WAI/Warp

Details

Language / Topic
haskellHaskell
Category
framework
Compatible Frameworks
scotty

Rules

balanced
- Start with `scotty 3000 routes` or get a WAI `Application` with `scottyApp routes >>= run 3000` from `warp`.
- Define routes with `get "/users/:id"`, `post "/users"`, `put`, `delete` — extract path params with `param "id" :: ActionM Text`.
- Return JSON with `json value` for any `ToJSON` instance — set `status status400` before calling `json` for error responses.
- Parse request JSON bodies with `jsonData :: FromJSON a => ActionM a` — wrap in `rescue (\_ -> status status400 >> json errBody)` for parse errors.
- Use `raise` to abort the current action with an error and `next` to fall through to the next matching route.
- Use `Web.Scotty.Trans` for a custom transformer stack: `scottyT 3000 (runReaderT ?? env) routes` — access the env with `lift ask`.
- Add WAI middleware with `middleware logStdoutDev` from `wai-extra` for request/response logging in development.
- Set headers with `setHeader "Content-Type" "application/json; charset=utf-8"` — must be set before `raw` or `text` calls.