API Design 2021
API Design 2021
• Introduction
• Why is API design important?
• Designing a REST API
• Hands-on exercise
• Guidelines for developing maintainable APIs
“defines the kinds of calls or requests that can be made, how to make them, the data formats that should
be used, the conventions to follow, etc.”
Remember!
Difficult to use, inconsistent and buggy APIs can lead to major
dissatisfaction in users and eventually lead to loss of business.
• A standardized interface - An interface that identifies resources, allows for the manipulation of
resources through representations, includes self-descriptive messages that describes how to process
requests and response, and dynamically identified hypermedia.
POST: Creates a new resource. Should return the URI of the created resource.
PATCH: Modifies an existing resource. Only needs to contain changes, not the whole resource.
HEAD: Requests resource metadata without retrieving the full resource representation.
API Specification
Provide a standard, clean, well documented, and easy to use API specification.
API Security
Only authorized users with secure credentials should be able to access the API.
Audit logging
To understand how the API is used or abused by its user, it is necessary to log the critical information
related to API usages.
Performance
A poorly performing API will not be used by its consumers and thus will cause a loss to the business.
Remember:
• Focus on the relationship between resources and sub-resources
• URIs should be nouns only. They do not contain any verb or operation.
Determine Representations
• Use plural nouns to address resources, e.g. /playlists for a collection of playlists. For resources that act
like functions, use verbs (e.g. /playlists/:playlistId/play).
• Do not use file extensions in resource names. Instead of using file extensions in resource names (e.g.
/users.json), the Content-Type header should be supported to retrieve resource representations in
different formats.
• Do not use HTTP operation names in resource names, e.g. prefer /pets over /get-pets.
Versioning
Idempotence
• For an operation to be idempotent, clients can make that same call repeatedly while producing the same
result.
• The PUT and DELETE methods are defined to be idempotent.
• POST method is not idempotent.
• The problem with DELETE, which if successful would normally return a 200 (OK) or 204 (No Content), will
often return a 404 (Not Found) on subsequent calls, unless the service is configured to "mark" resources
for deletion without actually deleting them.
• A device has the following attributes – id, name, configuration[], status(ON, OFF)
• A configuration has the following attributes – id, var1, var2, var3
siemens.com