Go to file
Maximilian Tagher 6d0b723eb1 [yesod-test] Adds requireJSONResponse function
This function checks that a response body is JSON, and parses it into a Haskell value. Having something like this function is pretty essential to using Yesod as a JSON API server, so I think it's a good addition. You can use it to parse a Haskell record directly (usually by adding FromJSON classes to your response types), or parse a Value and pull out individual fields, maybe using something like `aeson-lens` (though probably a testing-specific library would be better).

I debated over these things:

1. The name. I was thinking of something like [assert/require/decode/parse]JSON[Response/Body]. I ultimately went with requireJSONResponse:
	- decode/parse sound like the aeson functions that return Either or Maybe, and I wanted this function to throw an error if it failed
	- I'm open to using `assertJSONResponse`—it matches the other functions (`assertEq`) better—but I think it reads less like English.
	- I chose Response over Body because (a) It also checks the content-type header, which is not in the body (b) "Body" felt slightly in-the-weeds of HTTP; I think "response" is more approachable.
2. Should it require the JSON content type? You can definitely have a server that returns JSON without JSON content types, but I think that's a such a bad idea, it's more likely requiring it helps people if they accidentally don't add the header.
3. Should it take a String parameter to add to the error message? This would match `assertEq`, but other functions like `statusIs` don't take a message. Ultimately I went without it, because the messages felt like I was repeating myself: `(comment :: Comment) <- requireJSONResponse "the response has a comment"`
2019-11-24 15:31:05 -05:00
.azure Support for Cabal 3.0 2019-11-11 09:47:05 +02:00
.github stack list-dependencies is deprecated 2018-06-06 20:39:56 +05:30
demo Added an example with email auth and an ses mailer 2015-12-05 20:21:38 -07:00
yesod Add Getting Started to READMEs 2019-11-11 13:46:27 +01:00
yesod-auth Translated message "CurrentPassword" for russian language. 2019-10-26 23:08:38 +03:00
yesod-auth-oauth Fix typo in deprecation message 2018-12-27 17:31:58 -08:00
yesod-bin Support for Cabal 3.0 2019-11-11 09:47:05 +02:00
yesod-core Drop rio dep (fixes #1645) 2019-11-22 09:16:52 +02:00
yesod-eventsource deleted: unneed cabal build-depends by weeder 2018-06-09 13:15:21 +09:00
yesod-form Customize areq and wreq error message 2019-09-10 00:42:21 -05:00
yesod-form-multi Added Multi Input Form Functionality (#1601) 2019-08-16 04:30:20 +01:00
yesod-newsfeed Feedback fixes 2019-10-02 09:07:55 +02:00
yesod-persistent Replace call to connPrepare with getStmtConn (fixes #1635) 2019-10-29 13:25:53 +02:00
yesod-sitemap deleted: unneed cabal build-depends by weeder 2018-06-09 13:15:21 +09:00
yesod-static Strip CRs for Windows testing 2019-04-30 07:03:22 +03:00
yesod-test [yesod-test] Adds requireJSONResponse function 2019-11-24 15:31:05 -05:00
yesod-websockets Version bump 2019-05-21 12:10:03 -04:00
.gitignore Ignore stack.yaml.lock 2019-07-06 14:22:32 +12:00
CODE_OF_CONDUCT.md Switch CoC to Contributor Covenant 2017-12-06 16:02:01 +02:00
CONTRIBUTING.md Respond to @psibi's comments 2017-11-08 22:43:51 -08:00
Dockerfile add a Dockerfile for haskell development 2015-05-27 11:43:16 -04:00
LICENSE Switch to copyright year range #617 2017-02-27 09:47:45 +02:00
README.md Add Getting Started to READMEs 2019-11-11 13:46:27 +01:00
stack-lts-9.yaml Added Multi Input Form Functionality (#1601) 2019-08-16 04:30:20 +01:00
stack-nightly.yaml Reenable yesod-auth on nightly 2019-11-16 21:18:18 +05:30
stack-nightly.yaml.lock Reenable yesod-auth on nightly 2019-11-16 21:18:18 +05:30
stack-persistent-2-9.yaml Added Multi Input Form Functionality (#1601) 2019-08-16 04:30:20 +01:00
stack-persistent-2-10.yaml Added Multi Input Form Functionality (#1601) 2019-08-16 04:30:20 +01:00
stack.yaml Added Multi Input Form Functionality (#1601) 2019-08-16 04:30:20 +01:00
stack.yaml.lock Added Multi Input Form Functionality (#1601) 2019-08-16 04:30:20 +01:00

Build Status

Yesod Web Framework

An advanced web framework using the Haskell programming language. Featuring:

  • safety & security guaranteed at compile time
  • developer productivity: tools for all your basic web development needs
  • raw performance
    • fast, compiled code
    • techniques for constant-space memory consumption
  • asynchronous IO
    • this is built in to the Haskell programming language (like Erlang)

Getting Started

Learn more about Yesod on its main website. If you want to get started using Yesod, we strongly recommend the quick start guide, based on the Haskell build tool stack.

Here's a minimal example!

{-# LANGUAGE OverloadedStrings, QuasiQuotes, TemplateHaskell, TypeFamilies #-}

import Yesod

data App = App -- Put your config, database connection pool, etc. in here.

-- Derive routes and instances for App.
mkYesod "App" [parseRoutes|
/ HomeR GET
|]

instance Yesod App -- Methods in here can be overridden as needed.

-- The handler for the GET request at /, corresponds to HomeR.
getHomeR :: Handler Html
getHomeR = defaultLayout [whamlet|Hello World!|]

main :: IO ()
main = warp 3000 App

To read about each of the concepts in use above (routing, handlers, linking, JSON), in detail, visit Basics in the Yesod book.

Hacking on Yesod

Yesod consists mostly of four repositories:

git clone --recurse-submodules http://github.com/yesodweb/shakespeare
git clone --recurse-submodules http://github.com/yesodweb/persistent
git clone --recurse-submodules http://github.com/yesodweb/wai
git clone --recurse-submodules http://github.com/yesodweb/yesod

Each repository can be built with stack build.