Coder Social home page Coder Social logo

Comments (8)

jeevatkm avatar jeevatkm commented on May 2, 2024

@alexmontecucco Sorry for delayed response. Just got occupied with my aah framework work, getting ready to make an initial public release, etc.

When I designed the resty, I have followed convention of golang Setter. You can see that with every method exposed from resty for setting values.

I understand your question, I hope and believe it won't hurt to change these two SetFormData, SetQueryParam methods. Because resty already provides dedicated methods for setting multiple values SetMultiValueQueryParams and SetMultiValueFormData.

Now coming to your problem, as you have mentioned-

prevents from overriding existing keys.

Can you please explain me your use case where you unable to do so? The reason is if you're facing an issue other resty users could face. I would like to solve that.

Looking forward to your response.

from resty.

alexmontecucco avatar alexmontecucco commented on May 2, 2024

@jeevatkm Thx for you reply.
My concern is (from request.go):

// SetQueryParam method sets single paramater and its value in the current request.
// It will be formed as query string for the request.
// Example: `search=kitchen%20papers&size=large` in the URL after `?` mark.
// 		resty.R().
//			SetQueryParam("search", "kitchen papers").
//			SetQueryParam("size", "large")
// Also you can override query params value, which was set at client instance level
//
func (r *Request) SetQueryParam(param, value string) *Request {
	r.QueryParam.Add(param, value)
	return r
}

Both method name and doc are misleading because SetQueryParam is not setting but adding (r.QueryParam.Add(param, value)).
url.Values type has four functions: Get, Set, Add and Del.
It is still possible to achieve the desired result by not using the SetQueryParam function and directly use the QueryParam attribute of the Request object though.

from resty.

jeevatkm avatar jeevatkm commented on May 2, 2024

Thanks @alexmontecucco. Okay let's make the misleading clear.

I will do this in coming v0.12 release, I'm capturing it here so users can refer it -

  • SetQueryParam and SetFormData will be updated to use method Set internally

resty user have to use existing methods SetMultiValueQueryParams, SetMultiValueFormData for multi values which uses method Add internally.

I hope this doesn't affect users.

PS: If you're interested you can send PR for this update.

from resty.

alexmontecucco avatar alexmontecucco commented on May 2, 2024

I don't understand why SetMultiValueQueryParams and SetMultiValueFormData still need to use the Add internally. Is it to avoid breaking compatibility.

For SetQueryParam and SetFormData your suggestion is to simply change the Add to Set right ?

from resty.

jeevatkm avatar jeevatkm commented on May 2, 2024

No, it's not about breaking compatibility.

Yes, changing it from Add to Set for SetQueryParam and SetFormData.


The way Set works from url.Values is; it replaces the existing values. We will not able to add multi values. So Add is required for multi values.

Multi value method added on #28.

from resty.

alexmontecucco avatar alexmontecucco commented on May 2, 2024

Ok got it, I forgot, thx.
Will push something this week / weekend.

from resty.

jeevatkm avatar jeevatkm commented on May 2, 2024

Thanks @alexmontecucco.

from resty.

alexmontecucco avatar alexmontecucco commented on May 2, 2024

Closed by #71

from resty.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.