forwardemail / forwardemail/superagent
GET request with unencoded queryparams
- Dominant language
- JavaScript
- Stars
- 16.6k
- Forks
- 1.3k
- PR merge metrics
- No merged PRs in 30d
Description
I'm using NodeJS with Superagent to connect to an API.
The URL should look like this:
```
https://example.com/api/schedule/default/events?query={"jobSourceIds":["614999492641e60d523e1f51"],"status":["ready","notstarted"]}
```
I've tested this URL in Postman and it works fine.
But Superagent transforms this to:
```
https://example.com/api/schedule/default/events?query=%7B%22jobSourceIds%22:[%22614999492641e60d523e1f51%22],%22status%22:[%22ready%22,%22notstarted%22]%7D
```
The query-params are encoded which I don't want since my API can't process it.
The API ignores the params this way.
The queryParams are provided as a string in the right form.
I've tried to set the Content-type and request.type to JSON, but no luck.
Any suggestions on how to get this right?
```
var request = superagent[method.toLowerCase()](baseUrl + path);
request.set("Accept", "application/json");
request.set("Cache-Control", "no-cache");
// request.set('Content-Type', 'application/json')
request.set('Content-Type', 'application/x-www-form-urlencoded')
var headers = createHeaders(method, path);
Object.keys(headers).forEach(function (k) {
request.set(k, headers[k]);
});
request.proxyWrapper = function (proxy) {
if (proxy == undefined) return this;
return this.proxy(proxy);
};
console.log(queryParams) // query={"jobSourceIds":["614999492641e60d523e1f51"],"status":["ready","notstarted"]}
console.log(typeof queryParams) // string
return request.send(payload).query(queryParams).proxyWrapper(proxy).end(responseHandler);
```
Contributor guide
Research direction
Start at the request.send(payload).query(queryParams) call and trace how Superagent serializes string query arguments. Check existing query-handling tests, then define the expected behavior for this JSON query string and verify the resulting request URL matches the API's requirements.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100