What is Appery.io Server Code?

Server Code is one of the core components in the Appery.io platform and allows to write custom app logic. You write the app logic inside a server-side script which is executed on the server. The language used to write the script is JavaScript.

Server Code uses V8 JavaScript engine to execute the JavaScript on the server.

During development the Server Code script can be quickly tested inside editor.

When you are done writing the script, the script has a REST API URL which can be invoked from your app. In other words, a script is also a way to create a custom REST API.

You have access to pretty much all JavaScript objects. You also have built-in API that allows you to work and integrate with other Appery.io components as well as external systems. This is the built-in API list:

  • Console – used to print data for information or debugging purposes.
  • Collection – provides integration with the Appery.io database.
  • Database user – provides integration with the Users collection from Appery.io database.
  • Push  Notifications – used to send Push Notifications messages.
  • Request – holds request (input) information for the script.
  • Response – used as a response (answer) for the request.
  • ScriptCall – used to call another script.
  • XMLHttpRequest – used to send HTTP requests to web server and retrieve any type of data directly back into the script.
  • In Memory Data (IMD) – allows to store any data in fast memory for 20 minutes. It works like a very fast cache.

In addition to writing scripts, you can also create libraries. A library can include logic that can be included and re-used in other scripts.

Some examples using Server Code:

  • Run any custom logic/calculations.
  • Get data from the Appery.io database, process/format the data that makes sense for the app.
  • Send a targeted Push Notification message.
  • Check the database and if some condition is met (for example: low inventory), send a Push Notification message and email to the appropriate people.
  • Invoke an external REST API, process/format the response and return a result that make sense for the app.
  • Invoke two external REST APIs, combine the data in a format that makes sense for the app.
  • Write a script that registers and signs in a user from the app.

As mentioned at the beginning, a script is invoked via its REST API. You can also schedule a script to run periodically. It’s called a Job. For example, you can schedule a script to run once a day.

A script can be made secure which means a user login will be required before a script can be invoked. A user is created inside the Appery.io database Users collection.

With build-in versioning, a script version can be saved and restored at any point.

Server Code snippets and plug-ins provide sample code that can be quickly inserted into any script.

We have a number of short videos on using the Server Code on our YouTube channel here and here.

Happy coding.

Published by

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.