BossaBox

This is the playbook for engineering-playbook

REST API Design Guidance

Goals

Common API Design Decisions

The Microsoft REST API guidelines provide design guidance covering a multitude of use-cases. The following sections are a good place to start as they are likely required considerations by any REST API design:

Creating API Contracts

As different development teams expose APIs to access various REST based services, it’s important to have an API contract to share between the producer and consumers of APIs. Open API format is one of the most popular API description format. This Open API document can be produced in two ways:

Design-First Approach

A Design-First approach means that APIs are treated as “first-class citizens” and everything about a project revolves around the idea that at the end these APIs will be consumed by clients. So based on the business requirements API development team first start describing API designs as an Open API document and collaborate with the stakeholders to gather feedback.

This approach is quite useful if a project is about developing externally exposed set of APIs which will be consumed by partners. In this approach, we first agree upon an API contract (Open API document) creating clear expectations on both API producer and consumer sides so both teams can begin work in parallel as per the pre-agreed API design.

Key Benefits of this approach:

Planning a Design-First Development:

  1. Identify use cases & key services which API should offer.
  2. Identify key stakeholders of API and try to include them during API design phase to get continuous feedback.
  3. Write API contract definitions.
  4. Maintain consistent style for API status codes, versioning, error responses etc.
  5. Encourage peer reviews via pull requests.
  6. Generate server side boilerplate code & client SDKs from API contract definitions.

Important Points to consider:

Code-First Approach

A Code-First approach means that development teams first implements server side API interface code e.g. controllers, DTOs etc. and than generates API contract definitions out of it. In current times this approach is more widely popular within developer community than Design-First Approach.

This approach has the advantages of allowing the team to quickly implement APIs and also providing the flexibility to react very quickly to any unexpected API requirement changes.

Key Benefits of this approach:

Important Points to consider:

How to Interpret and Apply The Guidelines

The API guidelines document includes a section on how to apply the guidelines depending on whether the API is new or existing. In particular, when working in an existing API ecosystem, be sure to align with stakeholders on a definition of what constitutes a breaking change to understand the impact of implementing certain best practices.

We do not recommend making a breaking change to a service that predates these guidelines simply for the sake of compliance.

Additional Resources