Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Standardise middleware API responses #674

Closed
diego-G opened this issue Jul 17, 2017 · 0 comments
Closed

Standardise middleware API responses #674

diego-G opened this issue Jul 17, 2017 · 0 comments
Assignees

Comments

@diego-G
Copy link

diego-G commented Jul 17, 2017

Parent #899

The current Middleware does not implement an standardized API response. It needs to create a better Middleware according to the REST API standards. I suggest to follow http://jsonapi.org . This standard includes for example the possibility to introduce HATEOAS: referencing to another endpoints directly in the response (self link, related entity links, pagination links, etc). It offers to the user an smoothly navigation.

Also, setting this standard will allow us to have several developers working in parallel on same issues, overall the ones related to the API refactoring #457 #225 .

The proposed structure is as follows:

Success

HTTP/1.1 200 OK
Content-Type: application/json
{
  "meta": {
    "total-pages": 13
  },
  "data": [
    {
      "type": "articles",
      "id": "3",
      "attributes": {
        "title": "JSON API paints my bikeshed!",
        "body": "The shortest article. Ever.",
        "created": "2015-05-22T14:56:29.000Z",
        "updated": "2015-05-22T14:56:28.000Z"
      }
    }
  ],
  "links": {
    "self": "http://example.com/articles?page[number]=3&page[size]=1",
    "first": "http://example.com/articles?page[number]=1&page[size]=1",
    "prev": "http://example.com/articles?page[number]=2&page[size]=1",
    "next": "http://example.com/articles?page[number]=4&page[size]=1",
    "last": "http://example.com/articles?page[number]=13&page[size]=1"
  }
}

Error

HTTP/1.1 422 Unprocessable Entity
Content-Type: application/json

{
  "errors": [
    {
      "status": "422",
      "source": { "pointer": "/data/attributes/first-name" },
      "title":  "Invalid Attribute",
      "detail": "First name must contain at least three characters."
    }
  ]
}
@diego-G diego-G added this to the Version 1.0.0 milestone Jul 17, 2017
@diego-G diego-G changed the title Improving API Response Middleware Standardization API Response Middleware Jul 18, 2017
@karmacoma karmacoma modified the milestone: Version 1.0.0 Aug 9, 2017
@karmacoma karmacoma changed the title Standardization API Response Middleware Standardise middleware API responses Aug 9, 2017
@karmacoma karmacoma assigned nazarhussain and unassigned diego-G Nov 6, 2017
karmacoma added a commit that referenced this issue Nov 12, 2017
Standardise middleware API responses for /node and /peers endpoints - #674
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants