Skip to content

Instantly share code, notes, and snippets.

@holmberd
Last active August 18, 2018 04:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save holmberd/06f1d158844dd6a5f0dda147c56c6834 to your computer and use it in GitHub Desktop.
Save holmberd/06f1d158844dd6a5f0dda147c56c6834 to your computer and use it in GitHub Desktop.
Product REST API CRUD Responses

Responses

POST /api/v1/products

success-status: 201

failure-status: 400 (bad request), 500

{
  id: 1,
  name: 'twoot',
  ...
  links: [{
    href: https://myapi.com/api/v1/products/1,
    rel: 'self',
    'method': 'GET'
  }]
}

GET /api/v1/products/:id

success-response: 200

failure-status: 404, 500

{
  id: 1,
  name: 'twoot',
  ...
  links: [{
    href: https://myapi.com/api/v1/products/1,
    rel: 'self',
    method: 'GET'
  }]
}

DELETE /api/v1/products/:id

success-response: 204 (No Content)

failure-response: 404, 500

PUT /api/v1/products/:id

success-response: 200

failure-status: 400, 404, 500

{
  id: 1,
  name: 'twoot'
  ...
  links: [{
    href: https://myapi.com/api/v1/products/1,
    rel: 'self',
    method: 'GET'
  }]
}

GET /api/v1/products?offset=0&limit=2

success-response: 200

failure-status: 400, 500

{
  items: [
    {
      id: 1,
      name: 'twoot',
      ...,
      links: [{
        href: https://myapi.com/api/v1/products/1,
        rel: 'self',
        method: 'GET'
      }]
    },
    {
      id: 2,
      name: 'twoot2'
      ...,
      links: [{
        href: https://myapi.com/api/v1/products/2,
        rel: 'self',
        method: 'GET'
      }]
    }
  ],
  meta: {
    count: 2,
    offset: 0,
    limit: 2
    total: 10
  }
}

GET /api/v1

{
  links: [
  {
    href: https://myapi.com/api/v1,
    rel: 'self',
    method: 'GET'
  },
  {
    href: https://myapi.com/api/v1/products,
    rel: 'products',
    method: 'GET'
  }
  {
    href: https://myapi.com/api/v1/products/{id},
    rel: 'product',
    method: 'GET'
  },
  {
    href: https://myapi.com/api/v1/products/{id},
    rel: 'product',
    method: 'DELETE'
  },
  {
    href: https://myapi.com/api/v1/products,
    rel: 'product',
    method: 'POST'
  },
  {
    href: https://myapi.com/api/v1/products/{id},
    rel: 'product'
    method: 'PUT'
  },

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