You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Not only Postel's law is no longer considered as a good idea, but it does not
really apply to the specification. Our thinking has evolved here and we often
want a single way to do things, which makes things easier for everyone except
requests typed with curl.
Copy file name to clipboardExpand all lines: api-design-guidelines/requests-responses.md
-28Lines changed: 0 additions & 28 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -97,34 +97,6 @@ It's best to use the body for large or high cardinality variable-length request
97
97
- Large objects (Query DSL, aggregations, machine learning models)
98
98
- High cardinality variable length values (list of fields, indices, shards, document IDs)
99
99
100
-
## Adhere to the robustness principle
101
-
102
-
The robustness principle states:
103
-
104
-
> "be conservative in what you do, be liberal in what you accept from others"
105
-
106
-
This principle can apply in a number of ways, but in particular it can determine the design of API requests and responses. An API request may be built flexibly so as to allow both verbose detailed payloads and terse convenience payloads. The corresponding response, however, should always be structured predictably, and not depend on a particular syntax used within the request.
107
-
108
-
As an example, consider an API that looks up entities based on their ID. The request may be structured to allow either a single ID or a collection of IDs to be passed in. However, the API response should always return a collection of entities, even if that collection only contains one entity.
109
-
110
-
This principle allows for simpler consumer code that neither has to remember state between request and response, nor needs to "sniff" the output to determine its structure. If multiple variants of the response are truly desired, this may suggest that multiple API endpoints should be introduced, for example called `get_single_entity` and `get_multiple_entities`.
111
-
112
-
An example of this is the datafeeds API which accepts either a string or list of strings for indices but always returns a list of strings:
113
-
114
-
```yaml
115
-
PUT /_ml/datafeeds/feed-id
116
-
{
117
-
"indices": "index-name", // Input is a string.
118
-
...
119
-
}
120
-
121
-
GET /_ml/datafeeds/feed-id
122
-
{
123
-
"indices": ["index-name"], // Always returns a list of strings.
124
-
...
125
-
}
126
-
```
127
-
128
100
## Consider how client functions would wrap the API endpoint
129
101
130
102
It is common within client-side architecture to provide a one-to-one mapping between API endpoint and client language function. This simplifies implementation and documentation, provides good developer experience, and makes tracking of endpoint usage straightforward.
0 commit comments