Introduction to the JavaScript Service Provider
The JavaScript Service Provider (JSSP) allows you to generate new service types for K2 Cloud that appear alongside native service types already available in K2 Cloud environments. For example, K2 Cloud provides a service type that allows you to expose an Azure SQL database as SmartObjects. If you want to integrate with another technology that K2 Cloud does not provide an out-of-the-box connector for, you could use one of the generic service types (such as the REST Service Type) to integrate with the API exposed by the target system, or you could use JavaScript to write your own custom service type to integrate with the target system's API.
While using one of the generic service types does not require you to write any code, writing your own service type with the JSSP allows you full control over the behavior of the service type, and allows you more control over any processing that needs to happen when translating objects, properties and methods between the product and the target system. As opposed to the generic service types, the JSSP does not require you to serialize inputs and deserialize payloads like you have to do with the endpoint brokers, and particularly the REST broker. With the JSSP, you can handle all payload processing using JavaScript, giving you the flexibility to represent SmartObjects as the business objects that your business or customer understands and can more easily use in their solutions, without the added complexity of serialization and deserialization.
To learn more about the concepts and architecture of custom service types with JSSP in the product, see the topic Understanding Service Types, Service Objects and Architecture.
To get started with creating custom JSSP service types, see the topics Setting up your development environment and Understanding JavaScript Service Provider project structure. You can also refer to the available JSSP Sample Projects to see how to approach building a custom JSSP service type.
A goal of the JSSP is to enable everything you can do with a C#-based service type assembly with JavaScript code. (If you want to refresh your knowledge on custom brokers in K2 Five see the K2 Five Developer reference). Some of the concepts, methods, and approaches you use to build a custom JSSP are the same, but the implementation differs based on the language, where the extension projects resources are deployed to, and your version of K2 Cloud.
In K2 Five, you write all of your custom service types in C# and copy the assembly to the ServiceBroker folder for it to appear as a service type that you could then create an instance for and generate SmartObjects. The fundamental difference compared to K2 Five is that JSSP types are not associated with a compiled assembly that resides in the K2\ServiceBroker folder. Instead, the JSSP uses an internal service to execute JavaScript code (the JS code itself is hosted in URLs, typically GitHub locations) and the internal JSSP service engine exposes the JSSP service types to your environment as if they were assembly-based service types. Once the service type is registered, you can create an instance and generate SmartObjects just like with other service types in the product.
With the JSSP, you still use OnDescribe and OnExecute to describe your business objects and interact with the service, respectively. These methods however reside in your JavaScript code files. Essentially, the K2 Cloud is extended to perform an HTTP describe using REST and an HTTP execute using web sockets, eliminating the requirement for an assembly.