-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Rename HTTP::Params.from_hash to HTTP::Params.encode and add an overload for NamedTuple #4205
Conversation
src/http/client.cr
Outdated
@@ -418,8 +418,8 @@ class HTTP::Client | |||
# client = HTTP::Client.new "www.example.com" | |||
# response = client.post_form "/", {"foo" => "bar"} | |||
# ``` | |||
def post_form(path, form : Hash, headers : HTTP::Headers? = nil) : HTTP::Client::Response | |||
body = HTTP::Params.from_hash(form) | |||
def post_form(path, form : Hash|NamedTuple, headers : HTTP::Headers? = nil) : HTTP::Client::Response |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Format check failed, I believe spaces are required on type unions (Hash | NamedTuple
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, got a bit rusty I guess :)
9c81a02
to
e6ba387
Compare
|
@RX14 I find
I think in this case, |
@luislavena The consistency between them is that they have the type it's coming from in the same. They sound fine, from on it's own feels weird to me. Why not 2 seperate methods: |
What about |
Both How about we overload |
Oooh... I thought it returned an |
Or just |
e6ba387
to
07f0e85
Compare
src/http/params.cr
Outdated
def self.from_hash(hash : Hash) | ||
# Returns the given key value pairs as a | ||
# url-encoded HTTP form/query. | ||
def self.encode(hash : Hash) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should restrict to Hash(String, _)
. I know it isn't part of the initial PR intent.
If we want to work with any type of hash we can merge the implementation.
If we want to support only String key hashes we could restrict here and catch the compile time error sooner.
Hash(String, _)
sounds fine to me.
for NamedTuple Also allow passing NamedTuple to the corresponding post_form overloads on HTTP::Client
07f0e85
to
3bacc30
Compare
Alright, added the more specific restriction. |
Is this PR GTG? |
…s renamed to encode in crystal-lang#4205
…s renamed to encode in #4205
Also allow passing NamedTuple to the corresponding post_form overloads
on HTTP::Client
That should make passing some static form data (or even some data with static keys) more pleasant without sacrificing on performance as much.