Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"at" sign in parameter names in resource definition

Tags:

angularjs

from the documentation (http://docs.angularjs.org/api/ngResource.$resource):

$resource(url[, paramDefaults][, actions]);

paramDefaults(optional) – {Object=} – Default values for url parameters. ... If the parameter value is prefixed with @ then the value of that parameter is extracted from the data object.

The question is what data object do they refer to? How to use this feature?

like image 641
akonsu Avatar asked Nov 09 '12 18:11

akonsu


People also ask

What is a parameter in Azure?

Parameter and expression concepts You can use parameters to pass external values into pipelines, datasets, linked services, and data flows. Once the parameter has been passed into the resource, it cannot be changed. By parameterizing resources, you can reuse them with different values each time.

What are path parameters?

Path parameters are variable parts of a URL path. They are typically used to point to a specific resource within a collection, such as a user identified by ID. A URL can have several path parameters, each denoted with curly braces { } .

What are policy parameters?

Policy parameters are how you map required parameters. These parameters are defined in or referenced by the WSDL policy or are defined in an attached source for the DataPower® configuration. If you do not define all required parameters, processing a message with the defined WS-Policy generates errors.

How do you pass multiple parameters in swagger?

If you are trying to send a body with multiple parameters, add an object model in the definitions section and refer it in your body parameter, see below (works with editor.swagger.io):


1 Answers

lets say you have a resource like this:

var User = $resource('/user/:userId', {userId:'@id'});
var user = User.get({userId:123});

It means that the value of :userId in your url will be replaced with the id property from the user object when that property is required.

So when is it required? Its required when you are doing something to an existing user, like geting one, updating one. It is not required when you create a user.

In most cases, you will want to have at least one param prefixed with @ in your REST url that resource uses (probably the object id). If you dont have one, that means that in order for you to save an instance of an object, you dont need to know anything about where its stored. This implies that its a singleton object. Maybe like a settings object.

Here is your long awaited example:

var User = $resource('/user/:userId/:dogName', {userId:'@id', dogName:@dog});
User.get({userId:123, dog:'Matt'}, function() { .. })

will produce the request: GET /user/123/Matt

like image 175
mkoryak Avatar answered Oct 20 '22 05:10

mkoryak