liveBook · Manning

Import/export pattern

As explained in API Design Patterns

The import/export pattern is a reusable API structure for transferring substantial amounts of data into or out of a service while accommodating destinations, transformations, and asynchronous processing.

The import/export pattern structures large data transfers around configurable destinations, transformations, and asynchronous processing. It improves on a simple export endpoint that returns only a download location by making request choices reusable in the response and exposing operation progress. section 2.4.3

A practical design should:

  • Accept an output configuration containing a destination and optional compression or encryption settings. section 2.4.3
  • Represent the transfer as a long-running operation with completion state, results, errors, and percentage progress. section 2.4.3
  • Support destination variants such as a hosted file or an Amazon S3 location, while making access requirements explicit. section 2.4.3
Listing 2.3 Simple API to export messages
abstract class Twapi {
  static version = "v1";
  static title = "Twapi API";
 
  @post("/{parent=users/*}/messages:export")   #1
  ExportMessages(req: ExportMessagesRequest):
      ExportMessagesResponse;                  #2
}
 
interface ExportMessagesRequest {
  // The parent user of the messages to be exported.
  parent: string;                              #3
}
 
interface ExportMessagesResponse {
  // The location of a compressed file
  // containing the messages requested.
  exportDownloadUri: string;                   #4
}

Compare a simple message-export endpoint with the pattern-based design: the latter returns an operation rather than an immediate download URI. section 2.4.3

Exporting user messages

POST /{parent=users/*}/messages:export accepts an outputConfig specifying an Amazon S3 destination, gzip compression, and optional encryption. The response exposes the same configuration through an asynchronous operation, whose metadata reports progress from 0% to 100%. section 2.4.3

How API Design Patterns covers it

How deep it goes
Defines request configuration, operation metadata, destinations, compression, encryption, and errors, but leaves implementation details high-level.
Examples
Uses message export with hosted-file and Amazon S3 destinations, gzip compression, encryption settings, and percentage progress.
What you can do after
Operate configurable asynchronous exports, monitor progress, inspect errors, and retrieve results from selected destinations.
How it connects
Connects import/export with long-running operations, pagination, asynchronous processing, compression, encryption, and cloud storage.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of API Design Patterns. The section links point to the parts of the book it draws on.