Open rogerxu opened 5 years ago
Best Practices for Designing a Pragmatic RESTful API | Vinay Sahni
10 Best Practices for Better RESTful API | Thinking Mobile
All APIs MUST be versioned. Changes inside of a given API version MUST NOT lead to a compatibility break on the consumer side.
Whereas an API SHOULD keep the compatibility guarantee as long as possible, incompatible changes cannot be always avoided. In case of incompatible changes, the API owner MUST increase the API version to indicate the change.
Every API version MUST be represented as whole number (semantic versioning, like <major.minor.patch> MUST NOT be used). The version number increases sequentially in response to the need of introducing incompatible changes. This corresponds to the major part of a version notation in semantic versioning. Every API version MUST be part of the API URI. In the URI, the version MUST be encoded as a single decimal integer, which SHOULD be preceded by a small "v". The
Example:
https://api.domain.com/namespace-example/v1/users/123
The OpenAPI Specification, originally known as the Swagger Specification, is a specification for machine-readable interface files for describing, producing, consuming, and visualizing RESTful web services.
OAI/OpenAPI-Specification: The OpenAPI Specification Repository
The Best APIs are Built with Swagger Tools | Swagger
draft-wright-json-schema-00 - JSON Schema: A Media Type for Describing JSON Documents
allOf
anyOf
oneOf
not
items
additionalItems
properties
patternProperties
additionalProperties
Dict:
type: object
additionalProperties:
type: string
example:
foo: str1
bar: str2
type
enum
multipleOf
maximum
exclusiveMaximum
minimum
exclusiveMinimum
maxLength
minLength
pattern
maxItems
minItems
maxProperties
minProperties
required
nullable
discriminator
deprecated
format
4.4 Data Types - OpenAPI Specification
type | format | Comments |
---|---|---|
integer | int32 | signed 32 bits |
integer | int64 | signed 64 bits (long) |
number | float | |
number | double | |
string | ||
string | byte | base64 encoded characters |
string | binary | any sequence of octets |
boolean | ||
string | date | |
string | date-time | |
string | password | A hint to UIs to obscure input |
The OpenAPI Specification allows combining and extending model definitions using the allOf
property of JSON Schema, in effect offering model composition. allOf
takes an array of object definitions that are validated independently but together compose a single object.
While composition offers model extensibility, it does not imply a hierarchy between the models. To support polymorphism, the OpenAPI Specification adds the discriminator
field. When used, the discriminator
will be the name of the property that decides which schema definition validates the structure of the model. As such, the discriminator
field MUST be a required field.
userID
, getDBName
, getURL
, getSQLExpression
, ioChannel
.HttpRequest
, loadHtml
, smtpServer
.Note:
recalculateNodePresentationLayoutObjects()
Good: recalculateNodeLayouts()
getData()
Good: getAddress()
getRecordsCount()
Good: getRecordCount()
ClientProviderAuth
Good: ClientProviderAuthentication
GitHubUserGroup
Good: UserGroup
updateIfModified()
Good: update()
maxRowCountEnable()
Good: enableMaxRowCount()
code
tag./**
* This is the summary sentence.
* <p>
* This is the detailed description. Note that you can have
* multiple sentences in the detailed description.
* </p>
*
*/
Generation tools support tags of the following types:
@tagname comment
{@tagname comment}
<tag></tag>
/**
* Returns an Image object that can be painted on the screen.
* The url parameter must specify an absolute {@link URL}.
*
* @param url An absolute URL of the image
* @returns The image at the specified URL
* @see Image
*/
public Image getImage(URL url);
/**
* @param
* @return
* @throws
* @see
* @since
* @deprecated
* @version
*/
Error Handling - OData JSON Format Version 4.01
{
"error": {
"code": "INVALID_DATA", // required
"message": "Wrong data in the payload.", // required
"target": "payload",
"details": [
{
"code": "INVALID_TYPE", // required
"message": "Expected type array but found type object", // required
"target": "name"
}
]
}
}
Structuring validation errors in REST APIs - Brainly Engineering - Medium
validationResult() · express-validator
express-ajv-swagger-validation - npm
{
"result": "error",
"message": "Wrong data in the payload.",
"details": [
{
"code": "INVALID_TYPE",
"message": "Expected type array but found type object"
}
]
}
How to design better APIs (bluethl.net)
How to implement better APIs (bluethl.net)
REST API Tutorial
microsoft/api-guidelines: Microsoft REST API Guidelines
aisuhua/restful-api-design-references: RESTful API 设计参考文献列表,可帮助你更加彻底的了解REST风格的接口设计。
A Beginner’s Guide to HTTP and REST