Extending Web services

Siren Investigate provides an interface for developing plug-ins that extend Web services.

The plug-ins, which are called Web service drivers, are adapters for external APIs or functionality.

Siren Investigate uses Web service drivers to get data from these external APIs. Depending on the invocation type that you use, this data may also be stored in Elasticsearch.

Conceptually, a Web service driver provides access to a service group. Services are the different endpoints that a single vendor might expose.

For example, a service group called 'Google' might consist of 'WebSearch', 'ImageSearch', and 'NewsSearch' services.

Siren provides a generator package that you can use to develop a new Web service driver. We also provide tutorials, ranging from Beginners to Advanced, to get you started quickly.

Developing a Web service driver

The Siren Investigate generator package is written in Typescript and contains interfaces and functions for building and registering Web services. For more information, see the Typescript website.

Steps

  1. To install the generator package, run the following command:

    npm install @sirensolutions/web-service-interface
  2. Create a class that implements the ServiceDefinition interface. The required properties are:

    • name: The unique name of the service.

    • inputSchema: The input parameters that the service accepts when it is queried.

    • outputConfiguration: The outputs returned when it is queried.

  3. Configure the class to provide the invoke function, which is called when the service is queried. This function is given the parameters that are defined in the service’s inputSchema property and must return a list of results containing properties defined in the service’s outputConfiguration property:

    // MyService.ts
    import { InputSchema, OutputConfiguration, ServiceDefinition, SimpleMap } from '@sirensolutions/web-service-interface';
    
    export default class MyService extends ServiceDefinition {
      readonly name = 'my-service';
      readonly inputSchema: InputSchema = {
        input: { type: 'text' }
      };
      readonly outputConfiguration: OutputConfiguration = {
        output: 'text'
      };
    
      async invoke(params: { input: string }): Promise<SimpleMap> {
        // Query external API and return list of the results in the form of { output: 'response' }
      }
    }

    For more information, see the Service definition section of the API reference topic.

  4. Register the service on startup by calling the registerServices function in the index.ts:

    // index.ts
    import { registerServices } from '@sirensolutions/web-service-interface';
    import MyService from './MyService';
    
    export = registerServices('my-service-group', [MyService]);

    For more information, see the Registering Web services section of the API reference topic.