REST Routes¶
Backendless uses the following rules when creating REST APIs from method signatures:
| Method's name prefix |
HTTP command |
Route |
Argument(s) |
|---|---|---|---|
| addXXX( T ) |
POST |
/ |
JSON format of T sent in request body |
| setXXX( T ) |
PUT |
/ |
JSON format of T sent in request body |
| setXXX( int indexArg, T valueArg ) |
PUT |
/ |
JSON format of indexArg and valueArg in request body: { "indexArg" : value, "valueArg" : value } |
| deleteXXX( T ) |
DELETE |
/ |
JSON format of XXX sent in request body |
| getXXX() |
GET |
/ |
n/a |
| getXXX( int index ) |
GET |
/ |
The index argument must be sent as a query argument |
| none of the above - foobar() |
POST |
/ |
where:
<app ID> - Application ID from the Manage > App Settings screen in Backendless Console.
<REST API Key> - REST API Key for the application from the Manage > App Settings screen in Backendless Console.
<service name>- Service name as shown in Backendless Console. Service name is the same as the name of the service class.
<service version>- Version number/name assigned to service at the time when code is uploaded/published to Backendless.
Consider the following service:
package com.foo.shopping;
public class ShoppingService implements IBackendlessService
{
public void addItem( ShoppingItem item ) {
// skipping implementation for brevity
}
public ShoppingItem[] getCartItems() {
// skipping implementation for brevity
}
public boolean deleteItem( ShoppingItem item ) {
// skipping implementation for brevity
}
public double calculateTotal() {
// skipping implementation for brevity
}
}
Assuming the name assigned to the service is ShoppingService and version is 1.0, API Engine generates the following REST API routes for the service:
addXXX method:
Java signature:
public void addItem( ShoppingItem item )
REST API:
POST http://api.backendless.com/<API ID><REST API Key>/services/ShoppingService/1.0/Item
Request body: a JSON object representing ShoppingItem
getXXX method:
Java signature:
public ShoppingItem[] getCartItems()
REST API:
GET http://api.backendless.com/<API ID><REST API Key>/services/ShoppingService/1.0/CartItems
deleteXXX method:
Java signature:
public boolean deleteItem( ShoppingItem item )
REST API:
DELETE http://api.backendless.com/<API ID><REST API Key>/services/ShoppingService/1.0/Item
all other methods:
Java signature:
public double calculateTotal()
REST API:
POST http://api.backendless.com/<API ID><REST API Key>/services/ShoppingService/1.0/calculateTotal