Skip to content
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

Feature Request: Add API for specifying query parameters #3623

Closed
hesch opened this issue Mar 6, 2024 · 5 comments
Closed

Feature Request: Add API for specifying query parameters #3623

hesch opened this issue Mar 6, 2024 · 5 comments
Labels
feature new-http issues that would require (or benefit from) a new HTTP API

Comments

@hesch
Copy link

hesch commented Mar 6, 2024

Feature Description

I suggest adding a way to add query parameters to the http API. At the moment we need to construct the query parameter string ourselves in JS with something like this:

const queryParams = {
  param: 'val'
};

const queryString = Objects.entries(queryParams)
  .map(([key, val]) => `${key}=${urlencode(val)}`)
  .join('&');

http.get(`https://example.com/test?${queryString}`);

There is neither a way to specify the query params in the params parameter nor the urlencode function available.

Suggested Solution (optional)

In my opinion it would be pretty easy to add this feature by leveraging the already existing support in req.URL.Query(). The API on JS side would look something like this:

http.get(url, {
  queryParms: {
    param1: 'val',
    param2: 'val',
  },
});

On the go side the implementation would probably look something like this:

query := result.Req.URL.Query()
for _, key := range params.Keys() {
	str := params.Get(key).String()
	query.Add(key, str)
}
result.Req.URL.RawQuery = query.Encode()

Already existing or connected issues / PRs (optional)

No response

@hesch hesch added the feature label Mar 6, 2024
@github-actions github-actions bot added the triage label Mar 6, 2024
@joanlopez joanlopez removed their assignment Mar 18, 2024
@joanlopez joanlopez added awaiting user waiting for user to respond new-http issues that would require (or benefit from) a new HTTP API and removed triage labels Mar 18, 2024
@joanlopez
Copy link
Contributor

Hi @hesch,

First of all, thanks for contributing with this feature request, it's always nice to receive input from our lovely users.

As you may know, we're designing and planning the work for a New HTTP API, so we consider the current implementation (available at k6/http) as under maintenance only, so we're only committed to bug fixes. Anyway, I'm going to add the new-http label, so we may consider it as part of the new design.

However, I'm not sure if this actually needed, as we already have a JSLib that provides a similar API as the one you're asking for. Have you seen the url lib? 🤔 You can take a look at it at: https://grafana.com/docs/k6/latest/examples/url-query-parameters/

Do you still think that something like what you suggested is really needed? Or it's enough with the lib?

Thanks!

@hesch
Copy link
Author

hesch commented Mar 21, 2024

@joanlopez

Thank you for your feedback! I did not know about either the new HTTP API nor the url lib implementation. Thank you for pointing them out. In that case I would just suggest updating the current http documentation to include examples of the usage. That way it is easier for users to know about the url lib and how to work with it.

Regarding implementation of this for the new http-api, I would say it is a trade off between usability and keeping the implementation on the go side minimal. IMO this feature is so minimal that it might as well be implemented, but maybe this opens the floodgates for more and more features, eventually bloating the API.

BTW is there some timeline for the new HTTP module? Where is the primary discussion taking place? It seems like all the relevant issues are almost a year old at this point.

@joanlopez
Copy link
Contributor

Thank you for your feedback! I did not know about either the new HTTP API nor the url lib implementation. Thank you for pointing them out. In that case I would just suggest updating the current http documentation to include examples of the usage. That way it is easier for users to know about the url lib and how to work with it.

Thanks for the feedback! I'll let know our docs team about, so we'll see what can we do to make it more clear.
So far, I'd recommend you to take a look at our Examples section in docs, it's generally useful to discover this kind of "common" operations that aren't specifically covered by main docs.

BTW is there some timeline for the new HTTP module? Where is the primary discussion taking place? It seems like all the relevant issues are almost a year old at this point.

That's an internal ongoing discussion, so unfortunately I cannot share more details yet (no clear plans yet).
But we'll announce it once we have more concrete plans. Stay tuned!

@joanlopez joanlopez removed awaiting user waiting for user to respond triage labels Mar 21, 2024
@joanlopez
Copy link
Contributor

joanlopez commented Mar 22, 2024

Hey @hesch,

Quick update, as I forgot to share with you this issue, which I think is quite related to your feature request: #991

Do you think would be fair to close yours and keep that one? Or do you see any reason to keep this one as well? I can easily link this one in #991 comments to also keep it into consideration. Wdyt?

Thanks!

@hesch
Copy link
Author

hesch commented Mar 22, 2024

Let's close this in favor of the other Issue. It is basically the same issue! Thank you for the support.

@hesch hesch closed this as completed Mar 22, 2024
@oleiade oleiade removed the triage label Mar 22, 2024
@oleiade oleiade removed their assignment Mar 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature new-http issues that would require (or benefit from) a new HTTP API
Projects
None yet
Development

No branches or pull requests

4 participants