0.2.5 • Published 4 years ago

@daradermody/web-service-interface v0.2.5

Weekly downloads
-
License
GPL-3.0-or-later
Repository
github
Last release
4 years ago

= Developing a Web Service Driver

This package provides an interface for developing plugins used for extending web services in Siren Investigate. These plugins are called web service drivers and are adapters for external APIs or functionality. Siren Investigate then uses these web service drivers to get data from these external APIs. Depending on invocation type, this data may also be stored in Elasticsearch.

Conceptually, a web service driver provides access to a service group, which is a grouping of one or more functions called services. These functions 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.

TIP

To get started immediately, try our https://www.npmjs.com/package/@sirensolutions/generator-web-service[generator package] to create a new service driver.

====

To develop a web service driver, add this package as a dependency:

source,bash

npm install @sirensolutions/web-service-interface

This package is written in Typescript and contains interfaces and functions for building and registering web services. Once this dependency is added, created a class that implements the ServiceDefinition interface. This interface ensures that your service class provides all the properties and functions required by Investigate. Specifically, the properties required are:

  • name: The unique name of the service
  • inputSchema: The input parameters that the service accepts when queried (see <<input-schema,Input Schema>>)
  • outputConfiguration: The outputs returned when queried (see <<output-configuration,Output Configuration>>)

The class must also provide the invoke function, which is called when the service is queried. This function is given the parameters defined in the service's inputSchema property, and must return a list of results containing properties defined in the service's outputConfiguration property.

source,typescript

// 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' } }

}

Once the service is defined, you register it on startup by calling the registerServices function in the index.ts.

source,typescript

// index.ts import { registerServices } from '@sirensolutions/web-service-interface'; import MyService from './MyService';

export = registerServices('my-service-group', MyService);

The parameters of registerServices are as follows:

  • Service group name: Name of the group that groups the services together in the UI
  • List of web services: A list of classes that implement the ServiceDefinition abstract base class
  • Optional configuration schema: Used if the service group needs additional configuration (see <<service-configuration,Service Configuration>>)
0.2.5

4 years ago

0.2.4

4 years ago

0.1.18

5 years ago

0.1.17

5 years ago

0.1.16

5 years ago

0.1.15

5 years ago

0.1.14

5 years ago

0.1.13

5 years ago

0.1.12

5 years ago

0.1.11

5 years ago

0.1.10

5 years ago

0.1.9

5 years ago

0.1.8

5 years ago

0.1.7

5 years ago

0.1.6

5 years ago

0.1.5

5 years ago

0.1.4

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago