Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Documenting an API standard #403

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
82 changes: 82 additions & 0 deletions docs/standards/documenting-an-api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
---
layout: standard
order: 1
title: Documenting an API
date: 2024-04-09
id: SEGAS-XXX
tags:
- Software design
- API Design
related:
sections:
- title: Related links
items:
- text: Minimal documentation set for a product
href: /standards/minimal-documentation-set-for-a-product/
- text: How to document APIs
href: https://www.gov.uk/guidance/how-to-document-apis
- text: Writing API Reference Documentation
href: https://www.gov.uk/guidance/writing-api-reference-documentation
---
aaronrussellHO marked this conversation as resolved.
Show resolved Hide resolved

Documenting an API is an important part of the software design lifecycle. It helps consumers of your API, the wider community and even your own team understand the purpose of endpoints, what and how they work, inputs and outputs, what the requirements are to access it etc.

---

## Requirement(s)

- [You MUST include your API on the relevant registers](#you-must-include-your-api-on-the-relevant-registers)
- [You MUST have documentation on inputs and outputs of all endpoints](#you-must-have-documentation-on-inputs-and-outputs-of-all-endpoints)
- [You MUST provide specific feedback in responses](#you-must-provide-specific-feedback-in-responses)
- [You MUST document how to connect to your API](#you-must-document-how-to-connect-to-your-api)
- [You MUST document how to raise an issue with your API](#you-must-document-how-to-raise-an-issue-with-your-api)
- [You MUST document information on rate limits](#you-must-document-information-on-rate-limits)

aaronrussellHO marked this conversation as resolved.
Show resolved Hide resolved
### You MUST include your API on the relevant registers
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
### You MUST include your API on the relevant registers
### You MUST include your API on the relevant registers if your API is public


Listing our APIs contributes to the government community as well as other organisations and wider industry. Listing our APIs here will also help inter-departmental data exchanges, as well as sharing best practice in API development.

If your API is for internal or team use only, then it should be included in the internal API register.
aaronrussellHO marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
If your API is for internal or team use only, then it should be included in the internal API register.


If your API is public, it should also be on the [cabinet offices list of APIs](https://www.api.gov.uk/ho/#home-office).

### You MUST have documentation on inputs and outputs of all endpoints

Documenting the inputs and outputs of endpoints makes it easy for consumers to understand what is required and how to use the given responses from an endpoint.

It should include all of the following inputs that apply to your API:

- Request method
- URI query parameters
- Request headers
- Requirements for the request body

For each possible response, including error responses, you should document the following:

- Response status code
- Response headers
- The format of the response body

This can be achieved for a RESTful API by using [OpenAPI (Swagger v3)](https://www.openapis.org/what-is-openapi).

### You MUST provide specific feedback in responses
aaronrussellHO marked this conversation as resolved.
Show resolved Hide resolved

It's important that response is clear and gives a brief overview of what has happened when called an endpoint. For example. Access Denied or Cannot connect to database. Your documentation should also state what each status code represents.

This can make it easier to debug for any consumers.

A response should not include any information about the technologies used or any internal information for example internal server addresses etc.

### You MUST document how to connect to your API

You must have documentation in place explaining how you onboard users to your API, if your API requires authorisation, you must document how to get authentication keys.

### You MUST document how to raise an issue with your API

It's important to document how to raise an issue with your API, this not only helps your consumers with debugging or raising concerns, but enabled a feedback loop with your users.

### You MUST document information on rate limits

Rate limiting is important to secure your API and consumers may want to query your API often, so documenting the rate limits helps consumers build their software around these limits.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Rate limiting is important to secure your API and consumers may want to query your API often, so documenting the rate limits helps consumers build their software around these limits.
Rate limiting is important to secure your API and consumers may want to query your API often, so documenting the rate limits helps consumers build their software around these limits. This information may not want to be shared widely if rate limiting is in place for security reasons.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add where appropriate to sharing parts of the documentation more widely.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add to opening paragraph.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the rate limit being public is enough to make your application insecure, then it's not an adequate security measure. A malicious user can deterimine the limit through trial and error. Publishing the limit is not the issue, and makes your API harder to use for legitimate consumers.

A project can justify not meeting any part of any standard if their circumstances warrant it. This doesn't need to be a loophole encouraged by the standard.


aaronrussellHO marked this conversation as resolved.
Show resolved Hide resolved
---
Loading