haskell-servant / haskell-servant/servant
Servant Client from URL
- Dominant language
- Haskell
- Stars
- 2k
- Forks
- 427
- Avg merge
- 2d 23h
- Merged PRs (30d)
- 5
Description
Hiya,
I'm experimenting with an existing API, in which some JSON response objects have fields that point to URLs for related resources.
```
# Example for `Thing`
{
"user": "https://.../user/1"
"category": "https://.../category/2"
}
```
It seems, there's no immediate support inside servant to turn these URLs back into clients, did I miss something?
If not, is there any existing libraries/tooling to assist in me writing my own solution? I'm looking to write something along the following lines:
```hs
urlA :: BaseUrl -> Either Text (ClientM User)
urlB :: BaseUrl -> Either Text (ClientM Category)
urlA :<|> urlB = urlClient
liftAeson :: (BaseUrl -> Either Text a) -> Text -> Aeson.Parser (ClientM a)
liftAeson = ...
data Thing = Thing
{ ...
, relatedUser :: ClientM User
, relatedCategory :: ClientM Category
}
instance FromJSON Thing where
parseJSON = withObject $ \o -> do
relatedUser <- liftAeson urlA =<< o .: "user"
relatedCategory <- liftAeson urlB =<< o .: "category"
...
```
Contributor guide
Research direction
Start by reviewing Servant's client concepts and the Aeson parsing example in the issue. The payload names no files or tests and does not define whether the result should be core Servant support or a separate library; clarify the desired URL parsing, error behavior, and acceptance criteria before implementation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- haskell
- Domain
- api
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100