Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

sending api with limited fields in express

/*in controller
Api call url {{baseUrl}}/tours?fields=name,duration,price
*/

export.getAllTours= async(req,res)=> {
try{
  if(req.query.fields){
  const fields= req.query.fields.split(",").join(' ');
   let query= query.select(fields); //name duration price
  }
  
}catch(err){
  console.log(err)
}
}
 
PREVIOUS NEXT
Tagged: #sending #api #limited #fields #express
ADD COMMENT
Topic
Name
4+3 =