-
Notifications
You must be signed in to change notification settings - Fork 266
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parse query string comma-separated values as list #243
Comments
Hi @cmeeren, the way list items are passed through a query string is by specifying the parameter multiple times like in your second example. See #121 (comment) In this case ASP.NET Core has already decomposed the query string into a list and Giraffe is simply deserializing the string values into the correct type. Your client application has to send list items in the correct format I am afraid. EDIT: You could do your own hack by having a type like this: type Flag =
| Favorite
| Hidden
type Query =
{
Flags : string
}
member this.FlagList =
this.Flags.Split ','
|> Array.map (fun s ->
match s with
| "hidden" -> Hidden
| "favorite" -> Favorite
| _ -> failwithf "Could not deserialize string '%s'." s)
|> Array.toList |
Thanks for the tip. I too was under the impression that specifying the parameter multiple times was the correct way, but our front-end developer suggested using comma-separated values, so I just wanted to check if this was something Giraffe supported. It seems we should indeed stick to the standard way of doing things. |
On the other hand, the JSON API spec specifies that comma-separated values is mandatory behavior (link to first mention). Do you think it would be possible and desirable for Giraffe to add support for this? |
Good point - although I don't like JSON APIs specification, it should be easy to follow it. |
I am splitting manually. As a side note, I have also created FSharp.JsonApi, which makes JSON:API much more pleasant to use with F# (and optionally Giraffe). It has (among many other things) built-in helpers for parsing comma-separated query strings. (Don't use the package just for that feature, though.) |
All right, thanks for the info! |
I'd like to deserialize the query string
?flags=favorite,hidden
to the typeQuery
as defined below:Is this possible using Giraffe? I've only managed to use lists in query strings by repeating the parameter:
?flags=favorite&flags=hidden
.(Please disregard the actual DU related stuff; I've fixed that by using FSharpLu.Json.)
The text was updated successfully, but these errors were encountered: