Skip to content

Instantly share code, notes, and snippets.

@bengrunfeld
Last active May 2, 2019 05:34
Show Gist options
  • Save bengrunfeld/8bde3495a4354fc31d2cf782120186f7 to your computer and use it in GitHub Desktop.
Save bengrunfeld/8bde3495a4354fc31d2cf782120186f7 to your computer and use it in GitHub Desktop.
API Guidelines

REST API Guidelines

This is the set of guidelines that I use to build my API's. Borrows heavily from Google's API Design Guide and Github's REST Api Docs.

Endpoints

  • List endpoints with HTTP Verb, expected input, and reponse message and data types

Client Errors

Client errors generated by the API fall into one of three categories:

  1. Invalid format. e.g. Expected JSON but received String

  2. Invalid fields. e.g. Expected project_id but received tag_id

  3. Invalid field values. e.g. Expected project_id: <Number> but received project_id: <String>.

Error Codes

Codes follow Google API Design Guide. You can see a full list of Error Codes here: https://cloud.google.com/apis/design/errors#handling_errors

Standard Error Message

All errors should follow this format, where the properties are defined in a constants file.:

{
  code: errCode.ERROR_CODE,
  name: errName.ERROR_NAME,
  message: errMsg.ERROR_MESSAGE
}

Standard Success Message

All successful responses should follow this format:

{
  code: 200,
  message: 'Success'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment