简体   繁体   中英

Foxx Service Array handling

I have a database with documents and I would like to retrieve some data from it providing an array of keys to a Foxx service. It works using a single string but I'm missing something about implementing arrays.

UPDATED

router.get('/keys', function (req, res) {

    const keys = db._query(aql`
        FOR huis IN test
        FILTER huis._key in ${req.queryParams.keys}
        RETURN {
            'adres': huis.adres,
            'postcode': huis.postcode,
            'plaats': huis.plaats
        }
    `);

  res.send(keys);
})
.queryParam('keys', joi.array().required(), 'query to search for')
.response(joi.array()
    .items(
        joi.string().required()
    )
    .required(), 'List of house keys.')
    .summary('List house keys')
    .description('Makes LAT LNG from house keys.');

The joi.array() results in a nice interpretation by Arango on the Services overview page as shown below. But I handle it wrong because it returns a 404.

在此处输入图片说明

If you're passing an array, you will need to use a queryParam or bodyParam and not a pathParam.

I'd recommend change your router path to router.get('/keys', function (req, res) { and then access the value as req.queryParams.keys .

When you send the array via a queryParam you have a few options, either as /keys?keys=1234,5678 or as /keys?keys=1234&keys=5678 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM