Skip to content

CRUD API Examples

Zdravko Kolev edited this page Feb 27, 2023 · 1 revision

Northwind CRUD API

Swagger: https://data-northwind.indigo.design/swagger/index.html

Highlights:

  • Textbook REST example.
  • POST accepts the whole entity, even the "id", although it gets ignored and returns the created entity
  • PUT accepts the whole entity, even the "id"
  • DELETE methods need to map the id, like id=customerId
  • DELETE methods return a copy of the deleted entity

In order to create a Bearer token, use the POST -> /Auth/Register with the example request body:

{
  "email": "zkolev@infragistics.com",
  "password": "test",
  "confirmedPassword": "test"
}

This will return a token:

eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJJZCI6ImJmMzJkNTA4LTRkZWEtNDAyOC1hNTJkLWE0YzFmN2ZjODgwZiIsInN1YiI6Inprb2xldkBpbmZyYWdpc3RpY3MuY29tIiwiZW1haWwiOiJ6a29sZXZAaW5mcmFnaXN0aWNzLmNvbSIsImp0aSI6IjEzYzI4NDI1LTJlYjYt....

Google Tasks API

Doc: https://developers.google.com/tasks/reference/rest

Highlights:

  • No Swagger/OpenAPI, it uses their own Discovery Document format
  • POST accepts the whole entity, even the "id", although it gets ignored and returns the created entity
  • PUT requires the full entity, id is repeated in path and body
    • If id is missing in the body it fails
    • If title is missing in the body, it results in an empty title
  • PATCH: A partial entity can be sent
  • Delete body "must be empty", response empty

Azure DevOps:

Work items Doc: https://learn.microsoft.com/en-us/rest/api/azure/devops/wit/work-items?view=azure-devops-rest-7.1

Highlights:

  • POST requires some path parameters that might be resolved as a hardcoded values, e.g. "organization" or item "type"
  • important The Body of all operations is described as a JSON-Patch rather than a regular JSON object
  • Responses are regular JSON WorkItem

Pull Requests

Docs: https://learn.microsoft.com/en-us/rest/api/azure/devops/git/pull-requests?view=azure-devops-rest-7.1 Highlights:

  • Standard body format
  • Supports PATCH (not PUT)
  • important PATCH checks that supported params are sent in the body. e.g. trying to send pullRequestId results in "Invalid argument value.Parameter name: You can only update reviewers, descriptions, titles, merge status, and status"

Github issues:

Doc: https://docs.github.com/en/rest/issues/issues?apiVersion=2022-11-28

Highlights:

  • POST Sending id or number won't crash, just gets ignored
  • Supports PATCH (not PUT)
  • PATCH is forgiving, id, number or any other not supported field can be sent.

OData:

Doc: https://www.odata.org/getting-started/basic-tutorial/#modifyData

Highlights:

  • POST sends the entity, but consider that the entity "type" must be set as a static value
  • Prefers PATCH over PUT
  • No data is returned for PATCH, although this can be requested with additional query parms
Clone this wiki locally