Commit Graph

184 Commits

Author SHA1 Message Date
Teo Camarasu
a445fbafd6 Use CPP to avoid errors with old GHC from TypeApplications in class instance 2022-10-27 13:05:05 +01:00
Teo Camarasu
4627683a64 Fix TypeError for GHC-9.4
In GHC-9.4 the typechecker changed requiring more annotations in positions like this. See https://gitlab.haskell.org/ghc/ghc/-/wikis/migration/9.4#ambiguous-types-containing-a-typeerror and https://gitlab.haskell.org/ghc/ghc/-/issues/21149
2022-10-18 10:45:21 +01:00
Nicolas BACQUEY
77b92d0d7d Display capture hints in router layout
This commit introduces a `CaptureHint` type, which is passed as an extra
argument to the `CaptureRouter` and `CaptureAllRouter` constructors for
the `Router'` type.
`CaptureHint` values are then used in `routerLayout`, to display the
name and "type" of captured values (single or list), instead of just
"<capture>" previously.

N.B.:
Because the `choice` smart constructor for routers can aggregate
`Capture` combinators with different capture hints, the `Capture*Router`
constructors actually take a *list* of `CaptureHint`, instead of a
single one.
2022-03-23 14:30:45 +01:00
Julian Ospald
181e51db8a
Add MonadFail instance for Handler wrt #1545 2022-02-26 22:31:56 +01:00
Renzo Carbonara
61d0d14b5c servant-server: Fix build on GHC 9.2.1
The issue is similar to the one in #1513:

```
src/Servant/Server/Internal.hs:824:10: error:
    • Uninferrable type variable k0 in
      type family equation right-hand side: (TypeError ...)
    • In the type instance declaration for ‘ServerT’
      In the instance declaration for
        ‘HasServer ((arr :: a -> b) :> sub) context’
    |
824 |     type ServerT (arr :> sub) _ = TypeError (PartialApplication HasServer arr)
    |
```

This fix is similar to the one in #1514.
2022-02-04 14:34:12 +02:00
Gaël Deest
75cb9ac246 Add comment about slightly incorrect error message 2022-01-18 16:25:11 +01:00
Gaël Deest
aab7e0d5dd Custom errors for HasClient, HasServer 2022-01-18 16:25:05 +01:00
Giorgio Marinelli
29d2553e74
Derive HasClient good response status from Verb status (#1469) 2021-12-09 10:09:18 +01:00
Gaël Deest
f2bd982eaf Rename proof to g{Client,Server,Link}Proof 2021-11-18 10:25:36 +01:00
Gaël Deest
575aa70eca Cleanup 2021-11-18 10:11:45 +01:00
Gaël Deest
fca59556dd Code reorganization
Move `HasServer (NamedRoutes routes)` instance

The instance has been moved to `Servant.Server.Internal`, as the
instances for other combinators. It is necessary so that the instance
can be re-exported from `Servant.Server` without circular imports.

Otherwise, users have to import `Servant.Server.Generic` manually ;
forgetting to do so will produce confusing error messages about the
missing instance.

Move `HasClient (NamedRoutes routes)` instance

Moved so that the instance is made available when importing
`Servant.Client`, avoiding possibly confusing errors when
`Servant.Client.Generic` isn't imported.
2021-11-18 10:09:58 +01:00
Gaël Deest
861cd4f997 Exclude quantified constraints code for GHCJS
QuantifiedConstraints isn't available for GHC 8.4 (where our GHCJS
version is still stuck).

We may need to take a drastic decision for GHCJS at some point.
2021-11-18 10:09:58 +01:00
Gaël Deest
b0b02f1948 Implement HasServer (NamedRoutes routes)
We define `ServerT (NamedRoutes api) m` as `api (AsServerT m)`, so that
the server of an record-defined API is a record of handlers.

The implementation piggy backs on the instance for “vanilla” servant
types with `(:<|>)`, using the `GServantProduct` for converting backd
and forth between the record / vanilla servers.

The main difficulty is that GHC needs to know that this operation is
legit, which can be expressed as the fact that:

```
GToServant (Rep (ServerT (NamedRoutes api))) m ~
ServerT (GToServant (Rep (api AsApi))) m
```

plus a few additional constraints.

This is easy enough for `route`, as we know that `m ~ Handler`. But in
the case of `hoistServerWithContext`, the two involved monads are
unknown ; in other words, this constraint needs to hold `forall m.`

Switching `-XQuantifiedConstraints` on is not sufficient, as our
constraints involve type families (`Rep` and `ServerT`). Our trick is to
use an intermediary typeclass, `GServer`, as a provider of evidence (in
the form of a `Dict`) that our constraints are indeed satisfied for a
particular monad.

The only instance of `GServer` is defined along with it, so it is
practically invisible to users.
2021-11-18 10:09:58 +01:00
Maxim Koltsov
70f6c49524
Get rid of Unicode in err404 example (#1478)
ServerError field errBody uses ByteString, whose IsString instance kills
Unicode, thus turning example into garbage. Changed it to simple ASCII
string, since Unicode art did not exactly correspond to 404 error
anyway.

Fixes #1371
2021-10-31 14:36:57 +03:00
akhesaCaro
6e5dffbb91 unsupporting GHC < 8.6.5, removing unecessary imports 2021-10-02 13:13:24 +02:00
Brandon Chinn
799537f82d
Add serveWithContextT, ServerContext (#1441)
servant-server: add serveWithContexT and ServerContext
2021-08-21 19:15:02 +02:00
Paolo Capriotti
0f9cc7eeec
Add response header support to UVerb (#1420)
* Use type wrapped in Headers h to generate response

This avoids having to define MimeRender instances for Headers.
2021-06-10 17:10:50 +02:00
Andrey Prokopenko
ce638027a8
Remove extra parameter from haddock section of Fragment instances (#1362) 2020-11-22 11:08:32 +01:00
Felix Yan
aa4f54e92e
Correct a typo in UVerb.hs (#1363) 2020-11-22 11:08:11 +01:00
Andrey Prokopenko
da0c83d318
Add URI fragment as a separate combinator (#1324) 2020-11-18 21:57:20 +03:00
fisx
c1105899f4
union verbs (#1314) 2020-10-31 20:45:46 +01:00
Brandon Chinn
e364470dd9
Fix docs: emptyAPIServer -> emptyServer (#1344) 2020-10-01 09:58:50 +02:00
Maxim Koltsov
d740c18992
Explicit export list in ErrorFormatter.hs 2020-07-30 19:05:46 +03:00
Maxim Koltsov
57f0b0b390
Make error messages from combinators configurable
Currently there is no way for Servant users to customize formatting of
error messages that arise when combinators can't parse URL or request
body, apart from reimplementing those combinators for themselves or
using middlewares.

This commit adds a possibility to specify custom error formatters
through Context.

Fixes #685
2020-07-17 17:10:31 +03:00
Jan Hrcek
b9d8fbcdc1
Fix typos and grammar (#1304)
* Fix typos and grammar

* Remove redundant words, fix articles

* More language fixes

* More typo fixes and resolve TODO about missing links
2020-06-06 00:43:51 -04:00
Théophile Choutri
b3b3dc9f41 docs(generic): Improve the documentation for genericServerT
This commit adds an explanation and a link to the Servant Cookbook
to `genericServerT`.

Moreover, the `genericServer` and `genericServe`'s haddocks are
slightly edited to add a missing 'a'.
2020-03-04 15:53:37 +01:00
Ilia Rodionov
28c4533659 use queryString not rawQueryString, enables param rewrites with Middleware possible 2020-01-09 14:43:14 +02:00
Matthias Heinzel
069d087874 Fix compilation warnings 2019-12-15 17:04:06 +02:00
Catherine Galkina
b4372b5c14 Removed unnecessary OVERLAPPING/OVERLAPPABLE pragmas 2019-09-29 14:18:13 +03:00
Catherine Galkina
b440af900b Implemented NoContentVerb and server instances for it 2019-09-29 14:18:13 +03:00
Dmitry Ivanov
54812a9079
Fix the example in Servant.Server 2019-04-02 17:58:48 +02:00
jschaul
966ebe0169
Add support for Lenient|Strict Capture 2019-03-18 16:43:10 +01:00
Oleg Grenrus
48c5cc96a2 Split RouteApplication mega-module 2019-02-27 15:06:56 +02:00
Oleg Grenrus
a5655f8d5a Rename ServantError to ClientError, ServantErr to ServerError 2019-02-18 22:51:09 +02:00
Travis Staton
9d8a8118b8 Set http failure code priority explicitly 2019-01-06 11:02:38 -05:00
Oleg Grenrus
3001ed7990 Add mods to StreamBody 2018-11-09 21:49:53 +02:00
Oleg Grenrus
5f947d1c43 Bump version numbers
- Almost everything 0.15; also servant-foreign jumped to 0.15, for
  consistency
- Bump lower bounds of dependencies to most recent versions atm
- Use hspec-2.6.0
- Update `stack.yaml` accordingly
- Use base-compat a bit more
- Drop aeson-compat dependency (in tests and tutorial)
2018-11-09 20:20:26 +02:00
Alp Mestanogullari
56d95ae1ea
Merge pull request #1068 from cocreature/monadmask
Add MonadMask instance for Handler
2018-11-06 07:36:41 +01:00
Oleg Grenrus
45c1cbdfd5 Refactor Stream stuff
- Introduce SourceT, which is simple variant of "correct `ListT`".
  There are another variants possible (like in `streaming`),
  but I'm not sure there's much real difference.

- Introduce `Codensity`. There's a flag if people don't want to depend
  on `kan-extensions`.

- `StreamGenerator` and `ResultStream` are both `SourceT`.
  `Stream` combinator in `servant-client` uses `Codensity` for CPS.

- Add servant-machines, servant-conduit, servant-pipes
- Add streaming cookbook: just code, no explanations.
- Add a script to run streaming 'benchmarks'
2018-11-05 15:48:47 +02:00
Moritz Kiefer
95e66fa398 Add MonadMask instance for Handler 2018-11-03 21:41:23 +01:00
Kostiantyn Rybnikov
5620d2d781 Rename one function, run custom monad code from main 2018-10-26 13:05:46 +03:00
Kostiantyn Rybnikov
c1e15ef4c3 genericServeT and docs on using a custom monad with generics 2018-10-26 13:05:46 +03:00
Maximilian Huber
81f4db6c5c fix minor typo in deprecation warning 2018-08-04 17:16:02 +02:00
Oleg Grenrus
cfade67c2f Cleanup pre-GHC-8.0 stuff 2018-07-11 01:39:38 +03:00
Oleg Grenrus
88f8d3b0d1 Merge servant-generic 2018-07-05 23:21:25 +03:00
Oleg Grenrus
374a7b88fb Deprecate S.Utils.StaticFiles in favor of S.Server.StaticFiles 2018-07-05 23:20:59 +03:00
Oleg Grenrus
f9bcc15d0b Apply stylish-haskell on all modules 2018-06-29 23:36:39 +03:00
Oleg Grenrus
2c02287b6b Move Servant.Utils.Links -> Servant.Links. Fixes #997. 2018-06-25 14:27:17 +03:00
Jan van Brügge
dbbe9b7321 Allow to specify the status of streaming endpoints 2018-05-28 12:00:29 +02:00
Jan van Brügge
0ba09c999b Change definition of StreamGenerator 2018-05-24 05:08:48 +02:00