Jump to: navigation, search

Difference between revisions of "Governance/APIGuidelines"

(API Guidelines for Projects (DRAFT))
(HTTP Status Codes)
Line 39: Line 39:
 
a request in the data.
 
a request in the data.
  
 +
<br />
 
=== HTTP Status Codes ===
 
=== HTTP Status Codes ===
 
Projects should follow RFC 2616 http://tools.ietf.org/html/rfc2616
 
Projects should follow RFC 2616 http://tools.ietf.org/html/rfc2616
Line 51: Line 52:
 
* Out of quota errors ('''403 Forbidden'''). Do not use ''413 Entity too large''.
 
* Out of quota errors ('''403 Forbidden'''). Do not use ''413 Entity too large''.
 
* Do not use ''422 Unprocessable Entity''. Use '''400 Bad Request''' instead
 
* Do not use ''422 Unprocessable Entity''. Use '''400 Bad Request''' instead
 +
 +
 +
====Error documents====
 +
What to return in the response body when a request fails. This was proposed:
 +
 +
{ "error": { <br/>
 +
      "id": "<id of the error, a short string like user_not_found>",<br/>
 +
      "operation": "<short name for the operation, like add_user_to_group>",<br/>
 +
      "message": "Human language description of the problem.",<br/>
 +
      "data": { "id": "<the id of the object>", ...  }<br/>
 +
  }<br/>
  
 
=== Pagination and Filtering ===
 
=== Pagination and Filtering ===
 
TBD
 
TBD

Revision as of 08:30, 23 September 2014

API Guidelines for Projects (DRAFT)

The intent of this page is to provide guidelines for OpenStack projects for the look and feel of their REST API interfaces in order that we have a consistent look and feel across all the projects. Changing the APIs of older projects is a long term process as need to retain backwards compatibility for users, but over time we can all slowly converge to a more consistent API. The initial version of the document is broadly based on the discussions at the cross project API consistency session at the Juno Design summit https://etherpad.openstack.org/p/juno-cross-project-consistency-across-rest-apis

Note: This documentation is currently very much in development - an alpha version for discussion amongst those from the various projects who are interested in cross project API consistency. Feel free to add comments and guidelines you think we need to standardise on.


API Terminology

Common Issues

  • tenant vs project
    • We should always use project.
  • instances vs servers
    • We should always use servers.

Extensions

Use of API extensions is generally discouraged, though historically many projects have them. Where we have extensions we should from the API client point of view have them look the same. If a project supports extensions they should support the following features:

  • Versioning
    • All extensions should have client visible versioning to be able to signal changes to the API (both backwards compatible and backwards incompatible changes. Versioning may be of the form of versions on individual extensions or an api-wide microversion which allows clients to select a specific version of an API.
  • Discoverability mechanism
  • Extensions should be kept to a minimum. The core API should be reviewed regularly to incorporate features which were formerly extensions
    • Too many extensions results in portability issues

API Compatibility

Whether a change is considered backwards compatible or backwards incompatible is described here: https://wiki.openstack.org/wiki/APIChangeGuidelines

Accessing resources

Can we get some guidelines around when to use GET/PUT/POST/PATCH. And when to use URL parameters and when to specify a request in the data.


HTTP Status Codes

Projects should follow RFC 2616 http://tools.ietf.org/html/rfc2616

However there has been some ambiguity or misinterpretation. Below are some OpenStack specific guidelines:

Success Codes

  • For async like calls where the action is not completed before returning a response use 202 Accepted.

Failure Codes

  • Out of quota errors (403 Forbidden). Do not use 413 Entity too large.
  • Do not use 422 Unprocessable Entity. Use 400 Bad Request instead


Error documents

What to return in the response body when a request fails. This was proposed:

{ "error": {
      "id": "<id of the error, a short string like user_not_found>",
      "operation": "<short name for the operation, like add_user_to_group>",
      "message": "Human language description of the problem.",
      "data": { "id": "<the id of the object>", ...  }
  }

Pagination and Filtering

TBD