My React native front end needs to send an array as params in GET url to nodejs 0.17.x backend server. Here is the code in front end:
let url = `${GLOBAL.BASE_URL}/api/fortrades/bid4post?post_trade_id=${item.id}&bids=${_bids}`; //_bids is an array of integer [37]
let _res = await helper.getAPIp(url, _result, _params, "GET"); //fetch
Here is the code on backend server:
let bids = req.query.bids && req.query.bids !== [] ? req.query.bids : [];
console.log("bids in bid4post : ", `${bids} ${typeof(bids)} ${bids.length}`);
Here is the console outout which shows bids
as string
:
bids in bid4post : 37 string 2. //bids should be [37]. Here it is a string 37
What is missing here? Do I need to do bids.json()
to get the original array back?
CodePudding user response:
Trying changin' the parameter name from bids
to bids[]
let url = `${GLOBAL.BASE_URL}/api/fortrades/bid4post?post_trade_id=${item.id}&bids[]=${_bids}`;