haskell-servant / haskell-servant/servant

Add `Capture` variant to specify needed instances directly

Open
#708 3 comments 1 reaction 0 assignees View on GitHub
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.