public class RestContract
extends java.lang.Object
project.getObject = function (id, callback) {
callback(null, { ... });
};
helper.method(project.getObject, {
http: { verb: 'GET', path: '/:id'},
accepts: { name: 'id', type: 'string' }
returns: { name: 'object', type: 'object' }
})
The new route is GET /:id, instead of POST /project/getObject, so we
need to update our contract on the client:
contract.addItem(new RestContractItem("/:id", "GET"), "project.getObject");
| Constructor and Description |
|---|
RestContract() |
| Modifier and Type | Method and Description |
|---|---|
void |
addItem(RestContractItem item,
java.lang.String method)
Adds a single item to this contract.
|
void |
addItemsFromContract(RestContract contract)
Adds all items from contract.
|
java.lang.String |
getPatternForMethod(java.lang.String method)
Returns the custom pattern representing the given method string, or
null if no custom pattern exists. |
java.lang.String |
getUrl(java.lang.String pattern,
java.util.Map<java.lang.String,? extends java.lang.Object> parameters)
Returns a rendered URL pattern using the parameters provided.
|
java.lang.String |
getUrlForMethod(java.lang.String method,
java.util.Map<java.lang.String,? extends java.lang.Object> parameters)
Resolves a specific method, replacing pattern fragments with the optional
parameters as appropriate.
|
java.lang.String |
getUrlForMethodWithoutItem(java.lang.String method)
Generates a fallback URL for a method whose contract has not been
customized.
|
java.lang.String |
getVerbForMethod(java.lang.String method)
Gets the HTTP verb for the given method string.
|
public void addItem(RestContractItem item, java.lang.String method)
RestContractItem upsert = new RestContractItem("/widgets/:id", "PUT");
contract.addItem(upsert, "widgets.create");
contract.addItem(upsert, "widgets.update");
item - The item to add to this contract.method - The method the item should represent.public void addItemsFromContract(RestContract contract)
contract - The contract to copy from.addItem(RestContractItem, String)public java.lang.String getPatternForMethod(java.lang.String method)
null if no custom pattern exists.method - The method to resolve.null otherwise.public java.lang.String getVerbForMethod(java.lang.String method)
method - The method to resolve.public java.lang.String getUrlForMethod(java.lang.String method,
java.util.Map<java.lang.String,? extends java.lang.Object> parameters)
method - The method to resolve.parameters - Pattern parameters. Can be null.public java.lang.String getUrlForMethodWithoutItem(java.lang.String method)
method - The method to generate from.public java.lang.String getUrl(java.lang.String pattern,
java.util.Map<java.lang.String,? extends java.lang.Object> parameters)
"/widgets/:id" with the parameters
that contain the value "57" for key "id",
begets "/widgets/57".pattern - The pattern to render.parameters - The values to render with.