liveBook · Manning

Contract

As explained in Digital Twins in Action

An API is a defined interface through which software components access operations or data provided by another component.

An API is a defined interface through which one software component accesses another component’s operations or data. In a digital twin, APIs provide structured access to internal systems and external services. A twin can request specific data when needed rather than wait for a scheduled batch or stream. Some integrations run in the other direction: webhooks notify the twin of changes, while GraphQL subscriptions and WebSockets maintain connections for updates. section 4.4.3

Choose an API style to fit the exchange:

  • REST provides predictable, cacheable access to defined resources. section 4.4.3
  • GraphQL lets a twin request only the attributes it needs from a richer data model. section 4.4.3
  • gRPC offers type-safe, high-performance communication; WebSockets support persistent, bidirectional updates and control commands. section 4.4.3

Requesting satellite imagery

A Python request to NASA GIBS supplies a bounding box, date, image layer, dimensions, and PNG format to retrieve an image of Lake Kariba. The returned content is saved as a file. This is on-demand acquisition: the caller specifies the data it wants. section 4.4.3

Listing 4.8 Using the NASA GIBS RESTful API to retrieve an image of Lake Kariba
import requests
from datetime import datetime, timedelta

bbox = (26.5, -18.5, 29.0, -16.0)  #1
yesterday = (datetime.now() - timedelta(1)).strftime('%Y-%m-%d')

params = {
    'SERVICE': 'WMS',
    'VERSION': '1.1.1',
    'REQUEST': 'GetMap',
    'LAYERS': 'VIIRS_SNPP_CorrectedReflectance_TrueColor',
    'SRS': 'EPSG:4326',
    'BBOX': f'{bbox[0]},{bbox[1]},{bbox[2]},{bbox[3]}',
    'WIDTH': '1024',
    'HEIGHT': '640',
    'FORMAT': 'image/png',
    'TIME': yesterday,
    'TRANSPARENT': 'true'
}

response = requests.get(  #2
  'https://gibs.earthdata.nasa.gov/wms/epsg4326/best/wms.cgi',
  params=params)

filename = f'lake_kariba_{yesterday}.png'
with open(filename, 'wb') as f:
    f.write(response.content)

The listing shows the WMS request parameters, the requests.get call, and the saved response. section 4.4.3

An API is also an operational contract. Changes to schemas, rate limits, authentication, or versioning can break ingestion, so track specifications as dependencies and use versioning, tests, and monitoring to detect incompatibilities. Calls can also carry a recurring cost: an LLM API priced at $0.05 per decision costs $4.80 per day when called every 15 minutes. Model call frequency before putting an API in a frequent decision loop. section 4.4.3 section 10.3.5 section 8.5.3

Do not confuse an API used to exchange data with a digital twin model interface. A DTDL interface defines an entity’s properties, telemetry, and relationships; it describes the twin’s model rather than the request used to fetch an image. section 5.3.2 section 4.4.3

How Digital Twins in Action covers it

How deep it goes
Compares integration styles and works through a Python image request, then addresses contract changes without implementing an API server.
Examples
Uses a NASA GIBS image request and a per-decision LLM API cost comparison.
What you can do after
Apply it via Python requests to retrieve dated imagery, and monitor external API contracts for breaking changes.
How it connects
Connects APIs to digital twin ingestion, webhooks, GraphQL subscriptions, WebSockets, and software dependency management.

Also explained in

Compare how 44 books explain contract →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Digital Twins in Action. The section links point to the parts of the book it draws on.