Skip to content

Working with the Service

The instructions below apply to both modes of service execution (debug and deployment).

  1. Once the service is in the debug mode, Backendless generates the service's REST APIs and the native SDKs. You can see the service and its operations on the Business Logic > API Services screen. For the service reviewed in this guide you will see the following screen when the service is running in the debug mode:java-api-service-v4.zoom70
  2. Backendless Console lists all available service operations/methods. To see the details of an operation and to invoke it, click the operation name. For example, click the addItem method. When invoking the method from Backendless Console, the request body must be a JSON object which combines the shopping cart name and the item being added to the cart:
    {
      "cartName": "string",
      "item": {
        "objectId": "string",
        "product": "string",
        "price": 0,
        "quantity": 0
      }
    }
    
    . However, when the operation is invoked from a native client (Android, iOS, JS), method arguments will be represented by objects from the native programming environment. In other words, you do not need to convert everything to JSON when working with API Services, unless you use service's REST API.
  3. To invoke the addItem method from Backendless console, you will need to provide argument values. Click the model schema area to copy its contents to the to the argument value area:
    click-to-copy-schema
  4. Modify the argument value as shown below. The objectId element should be removed, it is not needed for this operation.

    {
      "cartName": "mycart",
      "item": {
        "product": "Hoverboard",
        "price": 499,
        "quantity": 1
      }
    }
    

  5. Click INVOKE to make an invocation of the method:
    js-invocation-result-v4

  6. Notice you can get a complete cURL request which executes the same REST API request by switching to the CODE section:
    curl-request-api-service
  7. To see the contents of the shopping cart, click the getItems method. Enter the same name for the shopping cart that was used in the addItem invocation ("mycart") and click INVOKE again:
    getitems-invoke-java-v4.zoom65
  8. The result is a JSON array of ShoppingItem objects (so far there is only one in the collection). This maps closely to the formal response type of the getItems() method in Java:

    public List<ShoppingItem> getItems( String cartName )
      {
        ShoppingCart shoppingCart = getCart( cartName );
    
        if( shoppingCart == null )
          shoppingCart = new ShoppingCart();
    
        return shoppingCart.getItems();
      }
    

  9. The final step is finalizing the purchase with an invocation of the purchase method. The method retrieves the shopping cart object from the server-side cache and stores all the ShoppingItem objects in the Backendless database. To invoke the method, click purchase in the list of method, enter the name of the shopping cart in the form and click INVOKE.
    invoke-purchase-v4.zoom60

    You can see the saved objects on the Data screen of Backendless Console. There are two data tables:

    Order table:
    order-table.zoom60

    ShoppingItem table:
    shopping-item.zoom60