You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently we have endpoint creators like single, singleBy and singleRead. The only way to write a custom parser is through singleRead and many libraries assume Read and Show instances are meant for developer-readable representations (exa. Data.UUID, ByteString, UTCTime) as well as using Read is just plain annoying.
Can we add an additional endpoint creator category like (String -> Maybe sid) -> Endpoint sid mid aid or Parser sid -> Endpoint sid mid aid for some assumed parser library (exa. attoparsec)?
The text was updated successfully, but these errors were encountered:
My current need is because I'm using UUIDs as resource identifiers and the current Data.UUID library only reads stringified UUIDs since it assumes Show and Read should serialize and parse valid Haskell expressions. So I need to write a custom Read instance for my newtypes.
There's definitely an opportunity to push more of this into rest, but I think there are at least two ways you can implement this with rest today:
You can use singleBy to return a Maybe UUID. Then in your handler you can throw an error on Nothing, copying what rest does (I think it throws IdentError (ParseError "some message")).
You can wrap your UUID in a newtype, and write a custom Read instance.
Changing this in rest would mean changing the Rest.Dictionary.Types.Ident type. We can probably write something more general that also covers the two current cases there.
Overall I'd like to see all conversions be of the form i -> Either e a. For the function in question you would then have String -> Either e a where e ~ String currently, but in the future it could be any type that can be converted to the error output type of the handler.
Currently we have endpoint creators like
single
,singleBy
andsingleRead
. The only way to write a custom parser is throughsingleRead
and many libraries assumeRead
andShow
instances are meant for developer-readable representations (exa. Data.UUID, ByteString, UTCTime) as well as usingRead
is just plain annoying.Can we add an additional endpoint creator category like
(String -> Maybe sid) -> Endpoint sid mid aid
orParser sid -> Endpoint sid mid aid
for some assumed parser library (exa. attoparsec)?The text was updated successfully, but these errors were encountered: