REST Routes

Top  Previous  Next

API Engine creates REST API routes based on the method names in the class marked as a service. The product uses the following rules when creating REST APIs.

Prefix of method's name

HTTP command

Route

Argument(s)

addXXX( T )

POST

/<app version>/services/<service name>/<service version>/XXX

JSON format of T sent 
in request body

setXXX( T )

PUT

/<app version>/services/<service name>/<service version>/XXX

JSON format of T sent 
in request body

setXXX( int indexArg, T valueArg )

PUT

/<app version>/services/<service name>/<service version>/XXX

JSON format of indexArg and 
valueArg in request body: 
 { 

    "indexArg" : value,

    "valueArg" : value

 }

deleteXXX( T )

DELETE

/<app version>/services/<service name>/<service version>/XXX

JSON format of XXX sent 
in request body

getXXX()

GET

/<app version>/services/<service name>/<service version>/XXX

n/a

getXXX( int index )

GET

/<app version>/services/<service name>/<service version>/XXX?index=value

The index argument must be 
sent as a query argument

none of the above - foobar()

POST

/<app version>/services/<service name>/<service version>/foobar

 

 

where:

<app version>        - Name of the version of the app where service is deployed

<service name>        - Name assigned to the service at the time when code is uploaded to Backendless

<service version>        - Version number/name assigned to service at the time when code is uploaded to Backendless

Example

Consider the following service:

'use strict';

class ShoppingCart {
  /**
   * @param {ShoppingItem} item
   */
  addItem(item) {
    // skipping implementation for brevity
  }

  /**
   * @param {ShoppingItem} item
   */
  deleteItem(item) {
    // skipping implementation for brevity
  }

  /**
   * @returns {ShoppingItem[]}
   */
  getCartItems() {
    // skipping implementation for brevity
  }

  /**
   * @returns {Number}
   */
  calculateTotal() {
    // skipping implementation for brevity
  }
}

Backendless.ServerCode.addService(ShoppingCart);

 

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:

 

Add an item to the shopping cart:

JavaScript function:

/**
 * @param {ShoppingItem} item
 */
addItem(item)

REST API:

POST http://api.backendless.com/<app version>/services/ShoppingService/1.0/Item
Request body: a JSON object representing ShoppingItem

 

Get items in the shopping cart:

JavaScript function:

/**
 * @returns {ShoppingItem[]}
 */
getCartItems()

REST API:

GET http://api.backendless.com/<app version>/services/ShoppingService/1.0/CartItems

 

Delete an item from the shopping cart:

JavaScript function:

/**
* @param {ShoppingItem} item
*/
deleteItem(item)

REST API:

DELETE http://api.backendless.com/<app version>/services/ShoppingService/1.0/Item

 

Calculate total for the items in the shopping cart:

JavaScript function:

/**
 * @returns {Number}
 */
calculateTotal()

REST API:

POST http://api.backendless.com/<app version>/services/ShoppingService/1.0/calculateTotal


Please let us know how we can improve the documentation by leaving a comment. All technical questions should be posted to the Backendless Support forum. We do not respond to the technical questions on the documentation pages.: