-
Notifications
You must be signed in to change notification settings - Fork 34
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
[PROPOSAL] Specialize Type used for Query String #198
Comments
@Xtansia WDYT ? |
@samuelorji This is something that we actually use in the client, for all of the API operations, for example: https://github.com/opensearch-project/opensearch-rs/blob/main/opensearch/src/cat.rs#L284-L320 So this isn't really something that's feasible to restrict the type of, nor is it desirable to restrict, as doing so forces a lot of overhead onto the caller to pre-convert everything to strings (you might have an array of ints, now you have to pre-emptively format them into a comma separated string), it also means you can't pass in a pre-formatted query string. |
Makes sense, I was thinking of only constraining it at the HTTP api layer here, while leaving the client / transport layer intact as they already handle query strings for the client. The restriction was for the raw and publicj http api that pretty much allowed any Serializable to be passed in. I see how it can be a little too restrictive, but yeah. really wish we could constrain the type in a non restrictive manner. Thanks, will close 👍 |
What/Why
What are you proposing?
Specializing the type of query "string" used in http queries by the client to make raw json requests
What users have asked for this feature?
None that I know of
What problems are you trying to solve?
Currently, the type of the query string is set to just basically any type that implements Serializable . While this doesn't look like a problem at initial glance, looking into the reqwest library that handles http calls, we can see that even if the type is
Serializable
it uses the serde url-encoded crate that will only serialize types that can be serialized into query strings. The request will fail with this error if theSerialize
type cannot be serialized into a query string.What sucks about this is that this problem cannot be caught at compile time, but at runtime. As an example, this is a valid struct that can be passed as a query "String" since it implements
Serialize
This will result in this error:
I'm proposing a solution where we specialize this query type to be a sequence of simple str key-value pairs for the client facing http method. I know it boxes users, but its safer to catch these errors at Compile time rather than at runtime
What is the developer experience going to be?
Better Compile time error checking
Are there any security considerations?
N/A
Are there any breaking changes to the API
Maybe some ?
What is the user experience going to be?
Users just have to supply query string as a sequence of str key-value pairs
Are there breaking changes to the User Experience?
Maybe ?
Why should it be built? Any reason not to?
To prevent clients from possible runtime errors
What will it take to execute?
A quite simple code change and some changes to the documentation
Any remaining open questions?
N/A
The text was updated successfully, but these errors were encountered: