Uploaded image for project: 'Red Hat 3scale API Management'
  1. Red Hat 3scale API Management
  2. THREESCALE-5095

JSON API uses related resource links that are not JSON endpoints

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Obsolete
    • Icon: Minor Minor
    • None
    • SaaS
    • System
    • Not Started
    • Not Started
    • Not Started
    • Not Started
    • Not Started
    • Not Started
    • Engineering
    • Workaround Exists
    • Hide

      Add the .json extension to the related resources' links to get back JSON output.

      Show
      Add the .json extension to the related resources' links to get back JSON output.
    • Hide

      1. Perform any valid request to a JSON endpoint returning resources.
      2. Call any related resource link to obtain that resource.

      Expected outcome:

      3. Get back the resource described in JSON.

      Actual outcome:

      3. Get back XML output from a link in a JSON response, and still get back XML even if explicitly asking for JSON output via the Accept header.

      Workaround:

      2. Append .json to the path of the links and perform the request.
      3. Get back JSON output.

      Show
      1. Perform any valid request to a JSON endpoint returning resources. 2. Call any related resource link to obtain that resource. Expected outcome : 3. Get back the resource described in JSON. Actual outcome : 3. Get back XML output from a link in a JSON response, and still get back XML even if explicitly asking for JSON output via the Accept header. Workaround : 2. Append .json to the path of the links and perform the request. 3. Get back JSON output.

      This is related to THREESCALE-4938.

      This is a minor issue with the links entry when the JSON API returns resources. Usually you can find there a set of related resources links, but the links provided do not use the .json extension (nor any other). Calling those endpoints results in XML being returned, and passing in the header Accept: application/json does not have any effect.

      Here's an example request returning links to related resources:

      curl -s -H "Accept: application/json" "https://istiodevel-admin.3scale.net/admin/api/services/2555417783508/metrics.json?access_token=<TOKEN>"
      
      {
        "metrics": [
          {
            "metric": {
              "id": 2555418218053,
              "name": "hits",
              "system_name": "hits",
              "friendly_name": "Hits",
              "description": "Number of API hits",
              "unit": "hit",
              "created_at": "2019-03-31T01:33:10Z",
              "updated_at": "2019-03-31T01:33:10Z",
              "links": [
                {
                  "rel": "service",
                  "href": "https://istiodevel-admin.3scale.net/admin/api/services/2555417783508"
                },
                {
                  "rel": "self",
                  "href": "https://istiodevel-admin.3scale.net/admin/api/services/2555417783508/metrics/2555418218053"
                }
              ]
            }
          },
        ]
      }
      

      Calling either the service or the self related endpoints results always in XML output no matter what you use as Accept header, as if the .xml extension was used (this is minor, and methinks this can be handled automatically by Rails, but endpoints that cannot return the acceptable format should be returning 406 Not Acceptable).

      The quick fix appears easy: add the .json extension to the related links.

              Unassigned Unassigned
              amartine@redhat.com Alejandro Martinez Ruiz (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Created:
                Updated:
                Resolved: