Developing JavaScript Services



Currently, HP provides webOS apps access to a rich set of application and system services available on the public bus. With webOS 2.0, third party developers can now "roll their own" services. Besides powering Synergy connectors, JavaScript services strengthen webOS's support for background processing and add new capabilities such as low-level networking, filesystem access and binary data processing to the webOS technology stack.

In this section:


Why Services?

Services can provide your app or apps with a number of distinct advantages:

Service examples:


JavaScript for Services

The popular Node.js runtime environment is built into webOS 2, allowing you to develop both webOS apps and services in JavaScript. Developers can write services using a rich set of JavaScript libraries. Besides the open-source Node.js, these include webOS's Node.js add-ons and Foundation libraries of utility JavaScript APIs.

Node.js

Figure 2: The Node.js Stack

Node.js is an event-driven I/O framework for the V8 JavaScript engine, intended for implementing scalable network programs such as web servers and streaming servers. Since Node apps do not require a UI or browser ("DOM" less) -- they run in their own instance of V8 -- they are more related to server-side JavaScript.

Node.js uses an event loop instead of threads, allowing it to scale to potentially millions of concurrent connections. It exploits the fact that servers spend most of their time waiting for I/O operations, which are much slower than in-memory operations. Every I/O operation in Node.js is asynchronous, which allows the server to continue processing incoming requests while I/O takes place in the background. This event-based model makes Node.js very fast, and makes scaling real-time applications very easy. JavaScript is extremely well suited to event-based programming because of its anonymous functions and closures, which make defining inline callbacks very simple.

In addition, the active Node development community provides support and a rapidly growing library of modules that you can use in your webOS services.

Foundations

Services (as well as apps) can take advantage of HP's Foundation libraries of JavaScript utilities. Foundations provides utilites for:

See the Foundations API reference for more information.


Next Steps

To begin understanding how to implement services, you should step through the Creating a Hello World Service procedure. Like all Hello World-type implementations, the intention is to strip the process down to a bare minimum, clearly showing what is involved and establishing a base for further development. Through this procedure, you will learn how to create and package a service, install it on the public bus, and call it from a JavaScript app.

After that, if you are interested in creating a Synergy connector with a JavaScript Synergy service, you can step through the Creating a Synergy Contacts Package tutorial. This will step you through the basics of creating and installing a Synergy app/service/account package, integrating with the webOS Contacts app, implementing a bare-bones Synergy service, and authenticating and syncing with an outside data source, in this case, Plaxo, an online address book and social networking site (www.plaxo.com).


Additional Documentation