Skip to content

What is a Service?

An API Service is a logical unit with one or more API endpoints. These endpoints are available in two formats:

  • via HTTP REST endpoint URI
  • via native SDK

Backendless automatically generates both types of endpoints for the deployed code. Access to an API Service is guarded by Backendless security, where individual service operations can be allowed or denied for application's users and roles. Additionally, Backendless gathers analytics for the service' API usage. The diagram below visually demonstrates these concepts:

What-is-API-Service

The workflow for developing and deploying a hosted service is very straight-forward:

  1. Developer writes the service code;
  2. Developer debugs and tests the service code using Backedless CodeRunner;
  3. Developer uses Backendless CodeRunner or Backendless Console to deploy the code;
  4. Backendless processes the deployed code and creates an API Service;
  5. Backendless automatically generates native client-side SDKs as well as REST API routes for the service operations.

Code deployed to Backendless automatically becomes an API service when it follows a set of simple rules documented below. For the code to be an API Service, it means it  is accessible through the standard networking mechanisms, such as generated REST API as well as native SDKs created by Backendless.

Developer must observe the following rules when creating service code:

  • Service class must contain at least one method. (Backendless generates API routes based on the methods declared in the class).
  • Service class must be registered with the following API:
Backendless.ServerCode.addService(SERVICE-CLASS);

Consider the following example:

class SampleService {
  /**
   * @param {string} zipCode
   */
  getWeather(zipCode) {
    // skipping implementation for brevity
  }

  /**
   * @return {number}
   */
  getServerTime() {
    // skipping implementation for brevity
  }

  /**
   * @param {string} to
   * @param {string} subject
   * @param {string} body
   */
  sendEmail( to, subject, body) {
    // skipping implementation for brevity
  }
}

Backendless.ServerCode.addService(SampleService);

Limitations

There are several considerations and limitations for the runtime behavior of the invoked methods:

  • The code cannot use native File IO, instead, it must be the Backendless File Service API to work with the application's file storage.
  • The execution time of a service method is limited for each Backendless Cloud pricing plan. Check the pricing table on the website for details. This limitation does not exist in the Backendless Pro and Managed Backendless versions of the service.