Jump to: navigation, search

Governance/Proposed/APIGuidelines

< Governance‎ | Proposed
Revision as of 00:00, 14 October 2014 by Morgan Fainberg (talk | contribs) (Error documents)

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
  • Naming.
    • Should follow the following format flavor-manage
    • Eg [a-z-]+
    • No contractions

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, HTTP headers or as data in the request body.

  • GET and HEAD must return the same exact information with exception of the body data (HEAD request does not return a body).
    • HEAD should not return a 204 if GET returns a 200 (for example)


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

POST body

  • snake_case rather than CamelCase should be used
  • when a parameter is dependent on an extension being loaded it should be prefixed with the extension name.
    • eg extension-name:parameter_name
    • This will avoid namespace clashes

Resource naming

  • resources should be formed of lower case characters and hyphens between words.
    • No contractions.