API Documentation

A guide for how to document the data structures and API definitions in the Building Block templates.

Each BB will be responsible for documenting the data structures and APIs that must be implemented by a candidate product. The documentation will be done iteratively, identifying a subset of the BB functionality and creating the specifications for how the functionality will be implemented.

This documentation is not technical, but rather an ‘English’ description of what the APIs do, what data they require and what data they return. From these documents, the more technical OpenAPI specifications can be created.

Data Structures

This section provides information on the core data structures/data models that are used by a Building Block. These data structures describe information that is exchanged between building blocks - they do not dictate internal data structures for a particular implementation. These data structures should also describe the minimum set of information that should be passed in an API call. The data structures can be extended for particular use cases.

These structures should be stored in the Building Block specification document in GitBook (section 7).

For each data model, the following information should be provided:

  • Name

  • Description

  • Fields - the various fields in this data structure. Each field definition should contain the following:

    • Name

    • Type (string, Boolean, number, date, etc)

    • Description

    • Foreign Key (does this field reference another data structure)

    • Constraints (does the field need to be unique, is it the primary key)

    • Required (Y/N)

    • You can also reference any standards that must be adhered to (ie. UTC standard for date/times)

APIs and Endpoints

Once the data structures have been defined, the APIs/endpoints that must be implemented for any compliant product can be described. The APIs should be defined using OpenAPI (Swagger) format and should be stored in the Building Block repository (in the /api directory). They can then be imported to the Service API section of the Building Block specification from the json or yaml file that contains the OpenAPI definition.

Data Structure Example

The following provides an example set of data structures. Note, the BB lead may use a tool like Lucid or Draw.io to develop a data structure diagram:

The data structures can also be defined as follows:

WorkList Data Structure:

Description: The WorkList data structure is used to track a list of subscribers to a particular session or event.

Fields:

Name

Type

Description

References

Constraints

Required

Name

Type

Description

References

Constraints

Required

id

int

Unique identifier for this WorkList

 

PK

Y

name

string

Name for this WorkList

 

Uniq

Y

status

enum

Status of the WorkList

 

 

Y

start_time

date

Start date/time for the WorkList

 

 

Y

end_time

date

End date/time for the WorkList

 

 

Y

alerts

integer array

Array of assigned alerts for this WorkList

Alert

FK

N

Notes: The status field is an enum that is defined with the following fields: ACTIVE, SUSPENDED, CANCELED

 

API Example

The following provides examples of API definitions. The OpenAPI definition can be extracted from these English definitions:

Endpoint: /alert

Method: GET

Description: Retrieves a list of alerts from the database

Arguments: None

Returns: An array of Alert data structures containing the data for each defined alert. See the data structures section for more detail

Responses:

200 - OK (the alert is successfully returned)

404 - Not Found (the alert cannot be found in the database)

Security: None

Method: POST

Description: Creates a new alert record in the the database

Arguments: Pass in the alert data structure as the POST body. See the data structures section for more detail. Note that the alert data structure should not pass in an ID as this will be generated.

Returns: The new Alert data structure, including the new ID for the alert

Responses:

200 - OK (the alert is successfully created and returned)

401 - Unauthorized (the user is not authorized to perform this action)

422 - Unprocessable Entity (the alert data structure passed in is invalid)

Security: Requires an auth token to be passed to the API. See the ‘auth’ API documentation for more information

Endpoint: /alert/{id}

Method: GET

Description: Retrieves a single alert from the database

Arguments: Pass in the unique ID for the alert as a path parameter

Returns: An Alert data structure containing the data for the specified alert. See the data structures section for more detail

Responses:

200 - OK (the alert is successfully returned)

404 - Not Found (the alert cannot be found in the database)

Security: None

Method: POST

Description: Updates an alert record in the the database

Arguments: Pass in the unique ID for the alert as a path parameter. Pass in the alert data structure as the POST body. See the data structures section for more detail.

Returns: The updated Alert data structure

Responses:

200 - OK (the alert is successfully updated and returned)

401 - Unauthorized (the user is not authorized to perform this action)

404 - Not Found (the alert cannot be found in the database)

422 - Unprocessable Entity (the alert data structure passed in is invalid)

Security: Requires an auth token to be passed to the API. See the ‘auth’ API documentation for more information