The CreatorCon Call for Content is officially open! Get started here.

Path Parameter Vs Query Parameter

NehaSNOW
Tera Guru

Hi Team,

 

Would like to know the difference between Path Parameter and Query Parameter with an example. 

 

I saw many answers in the Google but here I am looking about your understanding. Please share your own experience.

Also, would like to know how to decide which of them to use when?

 

Please suggest.

 

Thanks,

9 REPLIES 9

Peter Bodelier
Giga Sage

Path params are used to identify a specific resource, while query params are used to filter and sort the data. Path params are typically used when retrieving a single resource, while query params are used when retrieving multiple resources.


Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.

This answer is already available in the Google but not able to understand it. I want to know what we think about it as per our experience. Quoting with an example will be helpful for me to understand.

I think it is really self explanatory though.

 

If you need to update/get 1 record, use path. If you need to update/get multiple records, use query.


Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.

I can retrieve multiple records (via GET method) using Path parameters. 

 

(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
 
    // implement resource here
 
var answer = [];
 
var in_state = request.pathParams.state;
var incstate;
  
    switch (in_state) {
    case "New":
      incstate = 1;
      break;
    case "In Progress":
      incstate = 2;
      break;
    case "Pending":
      incstate = 3;
      break;
    case "Resolve":
      incstate = 4;
      break;
    case "Close":
      incstate = 5;
      break;
    case "Cancel":
      incstate = 6;
 
var incGR = new GlideRecord('incident');
    incGR.addQuery('state',incstate);
incGR.query();
 
while(incGR.next()){
 
var incObj ={
"Incident Number":incGR.getValue('number'),
"short description":incGR.getValue('short_description'),
"state":incstate
};
 
answer.push(incObj);
}
response.setBody(answer);
 
})(request, response);