haskell-servant / haskell-servant/servant
Add `Capture` variant to specify needed instances directly
- Dominant language
- Haskell
- Stars
- 2k
- Forks
- 427
- Avg merge
- 2d 23h
- Merged PRs (30d)
- 5
Description
In my library I want to use a type from an upstream library in my API definition. Unsurprisingly the upstream library does not define `ToHttpApiData` or `FromHttpApiData` on its data types. This means I am left with two simple options: introduce orphan instances or wrap this type in a `newtype`. Orphans are...well orphans. Using a `newtype` would mean that my downstream users have to wrap/unwrap simply to tell servant about the proper instances of an otherwise unrelated data type. In situations like this I find myself wanting a variant of `Capture` that doesn't rely on the type's instances but allows you to directly specify which instances to use (perhaps via some other type). For example:
```haskell
import Data.ISO3166_CountryCodes (CountryCode)
import Web.HttpApiData (FromHttpApiData)
newtype CountryCodeInstances a = CountryCodeInstances a
instance FromHttpApiData (CountryCodeInstances CountryCode) where
-- ...
type Api = CaptureWith CountryCodeInstances "country-code" CountryCode :> Get '[PlainText] ()
```
Contributor guide
Assessment
This issue has not been assessed yet.