liveBook · Manning

Common case

As explained in API Design Patterns

The common case is the frequent, typical usage scenario that an API should make especially easy to perform.

The common case is the frequent, typical usage scenario an API should make especially easy. Keep advanced capabilities available without making ordinary operations harder. section 1.4.3

Translation API

A direct call such as TranslateText("Hello world", "es") serves the ordinary translation task. Requiring users to detect a language, select a model, and pass a model ID exposes unnecessary complexity. An optional modelId preserves advanced control without burdening typical callers. section 1.4.3

Apply the pattern by:

  • Giving each distinct operation a method designed for its purpose, rather than hiding language detection inside translation. section 1.4.3
  • Choosing references or inline data according to typical usage, resource size, query cost, and likely growth. section 4.2.2
Listing 1.3 Translating text to a target language (the common case)
function translateText(inputText: string, 
                       targetLanguage: string, 
                       modelId?: string): string {
  return TranslateApi.TranslateText({
    text: inputText,
    targetLanguage: targetLanguage,
    modelId: modelId,
  });
}

Shows a common translation call with optional advanced model selection. section 1.4.3

How API Design Patterns covers it

How deep it goes
Compares direct and complex designs, then applies the rule to translation and resource representation choices.
Examples
Uses translation methods, language detection, model selection, and chat-room administrator representations.
What you can do after
Apply via API design by simplifying typical calls, isolating advanced options, and weighing inline-data trade-offs.
How it connects
Connects API simplicity, advanced features, edge cases, resource references, inline data, and resource growth.

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.