Skip to content

Instantly share code, notes, and snippets.

@diegovarussa
Created May 28, 2018 01:38
Show Gist options
  • Save diegovarussa/a340e849b17cfe30f6a757682c38c3b3 to your computer and use it in GitHub Desktop.
Save diegovarussa/a340e849b17cfe30f6a757682c38c3b3 to your computer and use it in GitHub Desktop.
API Creation Standards

Method GET

Get by ID, Get all, Get all with filter by query parameters

  • If find record return 200 with content.
{
    "my_data": "abcde fghijk",
    "create_time": "2018-04-05T02:47:29+00:00",
    "update_time": "2018-04-06T06:44:43+00:00"
}
  • If filter parameter fails return 422 with filter error message content.
{
    "my_data": {
        "regexNotMatch": "It is only allowed 'letters', 'numbers', '_', '.', '-'"
    }
}
  • If not find return 404 without content.
  • If find the record but from different root-user or sub-user return 404 without content.

Method POST

Create new record

  • Return 201 with created content.
{
    "my_data": "abcde fghijk",
    "my_data_hash": "584961dd27117db74e460b7c230b3ce327dc7fa1169434174a",
    "create_time": "2018-04-05T02:47:29+00:00",
    "update_time": "2018-04-06T06:44:43+00:00"
}
  • If filter parameter fails return 422 with filter error message content.
{
    "my_data": {
        "regexNotMatch": "It is only allowed 'letters', 'numbers', '_', '.', '-'"
    }
}

Method PATCH

Update created record

  • Return 200 with updated content.
{
    "my_data": "EDITED",
    "my_data_hash": "584961dd27117db74e460b7c2asdfaeste32asdc7fa1169434174a",
    "create_time": "2018-04-05T02:47:29+00:00",
    "update_time": "2018-04-06T06:44:43+00:00"
}
  • If filter parameter fails return 422 with filter error message content.
{
    "my_data": {
        "regexNotMatch": "It is only allowed 'letters', 'numbers', '_', '.', '-'"
    }
}
  • If not find the record to update return 404 without content.
  • If find the record but from different root-user or sub-user return 404 without content.

Method DELETE

Delete created record

  • Return 204 without content.
  • If filter parameter fails return 422 with filter error message content.
{
    "my_data": {
        "regexNotMatch": "It is only allowed 'letters', 'numbers', '_', '.', '-'"
    }
}
  • If not find return 404 without content.
  • If find the record but from different root-user or sub-user return 404 without content.

For not listed return values use:

{
    "message": "My error message!"
}

We are using this API Check List as our standard base for Rest APIs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment