If you find any errors, typos or have general feedback, select the text and click CTRL+ALT+ENTER.

Introduction

The Settings service allows you to save app information (such as API keys and URLs) into a settings file, and then reference the data from anywhere in the app. This also allows you to make changes in one place, rather than having to replace the same value everywhere in the app.

Creating a Settings service

By default, there is a Settings service added to your app. To create a new Settings service, from the Project view go: CREATE NEW > Service, check Settings (REST Settings), and click Create Service.

To create a parameter, enter its name and click Add:SettingsServiceAdded

It’s basically a properties file with key/value entries. You can also specify an optional description.

Using Settings service for dynamic values in REST services

A Settings service can be used for making values in  a REST service and URLs dynamic. For example, you can have the following URL, where the some part of it should be dynamic (should substituted from the Settings service):

  1. Create a new Settings service (if you don’t have one yet) by going to CREATE NEW > Service > Settings (REST settings).
  2. Then create a new parameter in the newly-created Settings , and provide a value for it.
  3. Now go to your REST service, and change the dynamic part of your URL to {SettingsName.parameterName} where SettingsName is the settings service name, and paramterName is the name of the parameter. Your URL should look like:

You can use the Settings service to substitute values in the URL, headers, query values and body values. For example if you want to dynamically substitute a parameter in the body of the POST request:

  1. Open your REST service and go to Request > Body. Right to the parameter you need (for instance, appId) type {MySettings.appId}.
  2. Go to your Settings service or create one if you don’t have one. Create an appId parameter,  and provide a value for it.
  3. Make sure your Settings service has exactly the same name that you specified in the request body (MySettings in this example).

You can also change the Settings service parameter values via JavaScript.

Read more about REST services and dynamic URLs here.

Using the Settings values in JavaScript

Settings service also supports JavaScript API which can be used to read from or write to in the Settings service.

The use of the methods listed below have been deprecated:

  • Apperyio.config()
  • Apperyio.configAdd()
  • Apperyio.getAll()
  • Apperyio.init()
  • Apperyio.remove()

These methods have been removed and replaced by their equivalents inside Apperyio.Config. Using the deprecated methods with v1.1 libraries will result in errors.

API methods are listed below.

Apperyio.Config.get( expression [, default_value] )

To retrieve data from settings:

      • expression – setting name or expression like SettingsName.database_url.
      • default_value – (optional) if settings name or expression can’t be found, then default_value will be returned.

Returns the value of setting or default_value (if specified).

Example:

Example:

Apperyio.Config.add( expression, value )

To add a new key-value to settings:

      • expression – setting name or expression such as SettingsName.database_url.
      • value – value for a setting.

It can be added for current runtime only, and doesn’t store anything to the app/constants.js file.

Example:

Apperyio.Config.all()

No arguments are needed.

Retrieves all of the available settings as an object.

Example:

Apperyio.Config.init( settings )

      • settings – replace or initialize Config service in the app.

In general this function shouldn’t be called since it runs at the start of application bootstrapping with all of the settings.

Example:

Apperyio.Config.remove( expression )

      • expression – setting name or expression like SettingsName.database_url.

Removes the setting from App settings.

It removes the setting for current runtime only, not from the app/constants.js file.

Example:

Incompatible changes

Keep in mind that the controller source code has lost the following:

      • $scope.name
      • $scope.screenName
      • the two code lines below:

It might affect the apps performance so make sure you make any of the necessary changes.