coder247
coder247

Reputation: 2943

calling a dojo JsonRest with parameters

When calling JsonRest using dojo, how can I pass parameters with it.

 var rest = new JsonRest({
                target: "/path/to/service"               
 });

Upvotes: 0

Views: 1123

Answers (1)

GibboK
GibboK

Reputation: 73918

JsonRest example:

require(["dojo/store/JsonRest"], function(JsonRest){
  // create a store with target your service
  var store = new JsonRest({
    target: "/path/to/service"
  });

  // make a get request passing some options
  store.query("foo=bar", {
    start: 5,
    count: 5,
    sort: [
      { attribute: "color", descending: true }
    ]
  }).then(function(results){
    // result here
  });
});

The function to use in your case is query with signature query(query, options)

When called, query will trigger a GET request to {target}?{query}, as described in dojo docs.

Please keep in mind that:

  • If query is an object, it will be serialized.
  • If query is a string, it is appended to the URL as-is.
  • If options includes a sort property, it will be serialized as a query parameter as well;

Your service/API should:

  • Return a array of objects in JSON format.
  • Return an empty array if no match is found.

Upvotes: 1

Related Questions