Skip to content

Abstract ByteString out of MIME rendering#1840

Closed
dmjio wants to merge 4 commits intohaskell-servant:masterfrom
dmjio:abstract-out-bytestring
Closed

Abstract ByteString out of MIME rendering#1840
dmjio wants to merge 4 commits intohaskell-servant:masterfrom
dmjio:abstract-out-bytestring

Conversation

@dmjio
Copy link
Member

@dmjio dmjio commented Aug 22, 2025

This should allow us to abstract over ByteString from the MimeRender / MimeUnrender classes, without breaking any code and preserving existing semantics, while gaining extensibility to other platforms.

On the client (e.g. browser) dealing with JSString / JSVal is often more efficient than marshalling by way of ByteString (at least for the JS backend). This change should be an easy win, keeping all existing code unaffected (via the type family defaulting rules), but allowing users on different platforms to use a type other than ByteString.

Usage would look like:

-- * when using servant-client on native platforms,
-- default to ByteString (existing code should be unaffected)
instance MimeUnrender JSON String where
  mimeUnrender Proxy = eitherDecode

-- * when using servant-client in the browser,
-- you can specify `JSVal`.
instance MimeUnrender OctetStream Blob where
  type MimeUnrenderType Blob = JSVal
  mimeUnrender Proxy = pure . Blob

@dmjio dmjio changed the title Abstract ByteString out of MIME rendering Abstract ByteString out of MIME rendering Aug 22, 2025
@dmjio dmjio force-pushed the abstract-out-bytestring branch from c147670 to 82bd8cc Compare August 22, 2025 16:46
@tchoutri tchoutri self-assigned this Aug 22, 2025
@dmjio dmjio changed the title Abstract ByteString out of MIME rendering Abstract ByteString out of MIME rendering Aug 31, 2025
@dmjio
Copy link
Member Author

dmjio commented Sep 2, 2025

I need to make use of this associated type family in servant-client-core (MimeUnrenderType/ MimeRenderType), to remove the ByteString specific assumptions, then https://github.com/haskell-miso/servant-miso-client can use servant-client-core as well (as opposed to rewriting the HasClient wheel here).

@tchoutri
Copy link
Contributor

tchoutri commented Sep 2, 2025

@dmjio A changelog entry would be really appreciated for this PR. :)

@dmjio
Copy link
Member Author

dmjio commented Sep 3, 2025

Okay so, I am temporarily deciding against this. Ended up making my own MimeUnrender / MimeRender classes to facilitate this instead. My classes are specialized to JSVal (https://github.com/haskell-miso/servant-miso-client). This PR would necessitate a lot more changes to servant-client-core than desired, there are more ByteString specific assumptions than I had previously realized in servant-client-core. Closing for now.

@dmjio dmjio closed this Sep 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants