ladjs / superagent

Ajax for Node.js and browsers (JS HTTP client). Maintained for @forwardemail, @ladjs, @spamscanner, @breejs, @cabinjs, and @lassjs.
https://ladjs.github.io/superagent/
MIT License
16.59k stars 1.33k forks source link

Filtering query with query method #1535

Open stefanO2602 opened 4 years ago

stefanO2602 commented 4 years ago

I´m creating a small Node.js application which calls some REST api´s using Superagent (v. 5.1.2). I need to send a filter option with a get request.

The API endpoint needs the following structure:

endpoint-url/test?filter=_name eq 'testname'

I´m struggling to achieve this result using superagent with the built-in query method. When I send the request I´ll get all items returned, so the filter option isn´t making any effect. Once I test it via postman I´ll get just the specified item returned with the _name = 'testname'. The variable name down in the code has the value 'testname'.

Here is my code snippet

superagent.get('endpoint-url/test').authBearer(token).query({'filter': '_name eq ' + name}) .then(res => {...}).catch(err => {...});