Skip to content

Added lookup functions for multiple files - #75

Merged
ysangkok merged 11 commits into
haskell-servant:masterfrom
tusharad:tusharad/added-lookup-functions
Sep 22, 2026
Merged

ysangkok merged 11 commits into
haskell-servant:masterfrom
tusharad:tusharad/added-lookup-functions

Conversation

@tusharad

Copy link
Copy Markdown
Contributor
  • Implemented lookupAllInputs to retrieve all textual inputs with a specific name attribute.
  • Implemented lookupAllFiles to retrieve all file inputs with a specific name attribute.
  • Implemented lookupInputAs to find a textual input and parse it into a desired type using FromText.
  • Implemented lookupAllInputsAs to find multiple textual inputs and parse them into a list of a specified type.
  • Added a FromText type class to facilitate parsing of various data types from Text.
  • Implemented instances for basic types like Text, Int, Bool, Double, Integer, Float, and Maybe a

Let me know if anything else is required. @maksbotan

Comment thread servant-multipart/src/Servant/Multipart.hs Outdated
Comment thread servant-multipart/src/Servant/Multipart.hs Outdated
Comment thread servant-multipart/src/Servant/Multipart.hs Outdated
Comment thread servant-multipart/src/Servant/Multipart.hs Outdated
Comment thread servant-multipart/src/Servant/Multipart.hs Outdated
@tusharad
tusharad requested a review from ysangkok September 19, 2026 19:18

@ysangkok ysangkok left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like the doctest syntax is invalid. Which doctest implementation did you use?

@tusharad

Copy link
Copy Markdown
Contributor Author

It seems like the doctest syntax is invalid. Which doctest implementation did you use?

I have converted all the examples to standard Haddock @ ... @ code blocks to match the rest of servant-multipart.

@ysangkok

Copy link
Copy Markdown
Contributor

Thanks. Is this intended to work with enctype='multipart/form-data' in HTML? Because it seems it would be unintuitive: A checked checkbox would be on (see MDN), which is not accepted as an encoding of True. And an unchecked checkbox would be absent, which is not supported by e.g. lookupInputAs @(Maybe ()), since the key must present. How are you imagining the use case? I am worried that the many ways one can encode data into multi-part forms means that there is no canonical single best way that can fit all writers. Somebody might prefer True/False, others will prefer on/off, and it will be hard to anticipate possible string encodings.

@tusharad

Copy link
Copy Markdown
Contributor Author

Hello @ysangkok

When writing the docstring, I had in mind a checkbox group sharing the same name with explicit value attributes, in which case lookupAllInputs returning list works as intended. I have clarified that in the docs.

You're right about standalone checkboxes "on" and absent keys are not suited for lookupInputAs.

If you feel lookupInputAs and lookupAllInputsAs introduce too many assumptions or edge cases , I am very happy to drop both and keep this PR strictly focused on the raw lookupAllInputs and lookupAllFiles functions.

Let me know what you think!

@ysangkok

Copy link
Copy Markdown
Contributor

I think it's fine to keep them. But could you add comments saying which functions take linear time. Because people could assume that functions named lookup would take constant time.

Comment thread servant-multipart/test/Test.hs Outdated
Comment thread servant-multipart/test/Test.hs Outdated
Comment thread servant-multipart/src/Servant/Multipart.hs Outdated
@fpringle

Copy link
Copy Markdown
Contributor

Following #80, I suppose these new functions (and their tests) will have to be moved to servant-multipart-api.

tusharad and others added 4 commits September 22, 2026 19:31
Co-authored-by: Frederick Pringle <frederick.pringle@fpringle.com>
Co-authored-by: Frederick Pringle <frederick.pringle@fpringle.com>
@tusharad
tusharad requested a review from ysangkok September 22, 2026 14:22
@tusharad

Copy link
Copy Markdown
Contributor Author

@fpringle I've moved lookup functions to api.

@fpringle fpringle left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@ysangkok
ysangkok merged commit d8fd27f into haskell-servant:master Sep 22, 2026
5 checks passed
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.

3 participants