Public API Design in Five Short Modules

This is a self-paced reading course for developers who maintain a library and want its public interface to survive several major versions. There is nothing to sign up for. Each module has a learning goal, the core ideas, a short reading drawn from well-known public material, and an exercise you can do on your own package in under an hour.

How to use this outline

Work through one module per sitting. Keep a scratch file open called API-NOTES.md in your repository and write down every decision you make; by the end it becomes the design notes section of your contributor docs. The examples refer to a hypothetical HTTP helper, Package C, but the ideas apply equally to Python, Go, Rust or JavaScript.

Module 1: Decide what is public

Goal: be able to list every name your package promises to keep stable.

Your public API is whatever users can reach without hacks: exported names, documented options, error types, CLI flags and, in JavaScript, any path allowed by the exports map. Semantic Versioning only works once you declare this surface, which the semver.org specification states explicitly. Anything undeclared will be treated as public by someone.

Reading: the introduction and rule 1 of the Semantic Versioning 2.0.0 specification.

Exercise: generate a list of everything your package exports. Mark each item "keep", "internal" or "unsure". Plan to hide the internal ones behind a private module or an underscore prefix.

Module 2: Names and shapes

Goal: choose names that read well at the call site and stay consistent.

Reading: the naming sections of your language's official style guide, such as PEP 8 for Python or Effective Go.

Exercise: rewrite three call sites from your README using only the names. Could a newcomer guess what each does?

Module 3: Errors are part of the contract

Goal: make failures predictable and catchable.

Users write code against your errors as much as your return values. Document which error types or codes each function can raise, give them stable identifiers (a code property or a dedicated exception class), and never rely on message text as the only signal. Changing an error type later is a breaking change for anyone catching it.

Exercise: list every error Package C's main function can produce. If you cannot, that is the finding.

Module 4: Designing for extension

Goal: leave room to add features in minor releases.

Return objects rather than bare tuples or arrays, so you can add fields later. Accept options objects so new options are additive. Avoid exposing classes that users are expected to subclass unless you are ready to support every overridable method forever. Each of these choices turns a future breaking change into a minor one.

Exercise: find one function whose return type you could not extend today and sketch the alternative.

Module 5: Evolving without breaking

Goal: have a written process for change.

  1. Add the new API alongside the old one.
  2. Deprecate the old one with a runtime warning and a note in the docs.
  3. Remove it only in the next major, with a migration entry.

Reading: our migration guide tutorial and the semver edge cases FAQ.

Exercise: write a three-sentence deprecation policy for your package and put it in the README.

After the course

You should finish with an explicit list of public names, a naming convention, a documented error contract and a deprecation policy. None of these needs tooling to start; they need decisions written down. Revisit the notes file before every major release.