{"action":"closed","issue":{"url":"https://api.github.com/repos/json-api/json-api/issues/1118","repository_url":"https://api.github.com/repos/json-api/json-api","labels_url":"https://api.github.com/repos/json-api/json-api/issues/1118/labels{/name}","comments_url":"https://api.github.com/repos/json-api/json-api/issues/1118/comments","events_url":"https://api.github.com/repos/json-api/json-api/issues/1118/events","html_url":"https://github.com/json-api/json-api/issues/1118","id":189488371,"number":1118,"title":"How to handle endpoints that don’t return a resource object(s) as its primary data","user":{"login":"andrewmtoy","id":1621615,"avatar_url":"https://avatars3.githubusercontent.com/u/1621615?v=4","gravatar_id":"","url":"https://api.github.com/users/andrewmtoy","html_url":"https://github.com/andrewmtoy","followers_url":"https://api.github.com/users/andrewmtoy/followers","following_url":"https://api.github.com/users/andrewmtoy/following{/other_user}","gists_url":"https://api.github.com/users/andrewmtoy/gists{/gist_id}","starred_url":"https://api.github.com/users/andrewmtoy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andrewmtoy/subscriptions","organizations_url":"https://api.github.com/users/andrewmtoy/orgs","repos_url":"https://api.github.com/users/andrewmtoy/repos","events_url":"https://api.github.com/users/andrewmtoy/events{/privacy}","received_events_url":"https://api.github.com/users/andrewmtoy/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":9,"created_at":"2016-11-15T19:48:40Z","updated_at":"2017-11-27T20:17:08Z","closed_at":"2017-11-27T20:17:08Z","author_association":"NONE","body":"Hi everyone,\r\nI am writing an api that exposes an Elastic Search api and was hoping to format the response using the JSON API Spec.\r\n\r\nCurrently the api looks like this:\r\n------\r\n#### Historical percentiles\r\n\r\n* Example:\r\n`/historical_percentiles?field=someField&start_time=1478810146&end_time=1478810158&bin_interval=second`\r\n\r\nReturns the percentiles for a field over a range of time.\r\n\r\n* Parameters:\r\n    * __start_time__ (required) Unix epoch time\r\n    * __end_time__ (required) Unix epoch time\r\n    * __field__ (required)\r\n    * __bin_interval__ (required) Elastic Search compatible interval string\r\n    * __filters__ (optional)\r\n\r\n```JSON\r\n{\r\n  \"meta\": {\r\n    \"time_to\": \"2016-11-05T01:34:31.597836+00:00\",\r\n    \"time_from\": \"2016-10-08T01:37:51.597836+00:00\",\r\n    \"bins\": [\r\n      {\r\n        \"5.0\": 361.5706796497282,\r\n        \"25.0\": 729.7459890881007,\r\n        \"1.0\": 327.0,\r\n        \"95.0\": 5520.63477722484,\r\n        \"75.0\": 2844.4385814706948,\r\n        \"date\": \"2016-10-08T00:00:00.000Z\",\r\n        \"99.0\": 8380.986835876729,\r\n        \"50.0\": 1617.47585721036\r\n      },\r\n      {\r\n        \"5.0\": 365.73289647286674,\r\n        \"25.0\": 779.2334616130121,\r\n        \"1.0\": 328.0,\r\n        \"95.0\": 5440.772302540405,\r\n        \"75.0\": 2795.7787375257903,\r\n        \"date\": \"2016-10-09T00:00:00.000Z\",\r\n        \"99.0\": 8345.435844243311,\r\n        \"50.0\": 1819.0584232227932\r\n      }\r\n    ]\r\n  }\r\n}\r\n```\r\n\r\nIdeally, I would like to wrap the payload in the data property, but JSON API spec requires that data returns a resource or resources, which must have an id and type.\r\nThe only performant way (that I can think of) to have an id for this payload would be to base64 encode the endpoint with query params.\r\n\r\n`/historical_percentiles/base64encodedEndpointWithQueryParams`\r\n\r\n```JSON\r\n{\r\n  \"data\": {\r\n    \"id\": \"base64encodedEndpointWithQueryParams\",\r\n    \"type\": \"historical_percentiles\",\r\n    \"time_to\": \"2016-11-05T01:34:31.597836+00:00\",\r\n    \"time_from\": \"2016-10-08T01:37:51.597836+00:00\",\r\n    \"bins\": [\r\n      {\r\n        \"5.0\": 361.5706796497282,\r\n        \"25.0\": 729.7459890881007,\r\n        \"1.0\": 327.0,\r\n        \"95.0\": 5520.63477722484,\r\n        \"75.0\": 2844.4385814706948,\r\n        \"date\": \"2016-10-08T00:00:00.000Z\",\r\n        \"99.0\": 8380.986835876729,\r\n        \"50.0\": 1617.47585721036\r\n      },\r\n      {\r\n        \"5.0\": 365.73289647286674,\r\n        \"25.0\": 779.2334616130121,\r\n        \"1.0\": 328.0,\r\n        \"95.0\": 5440.772302540405,\r\n        \"75.0\": 2795.7787375257903,\r\n        \"date\": \"2016-10-09T00:00:00.000Z\",\r\n        \"99.0\": 8345.435844243311,\r\n        \"50.0\": 1819.0584232227932\r\n      }\r\n    ]\r\n  }\r\n}\r\n```\r\n\r\nI don't like this method for a number of reasons: \r\n1.  the id could take up more space than the actual data being returned eg. (user enters many filters and one bin is returned)\r\n2.  the documents are stored for a finite period of time; the user would not be able to retrieve the same resource again after some period of time by using the id and type.\r\n3.  added complexity and redunancy of having to handle query params and base64 encoded id\r\n4.  frequency of use, I doubt the consumers of this api would ever use the id to retrieve data\r\n\r\nBecause of these reasons, I've put it in meta for now.  My reasoning is the api is returning data about stored data, which technically is meta data of the resource.\r\n\r\nIs there a better way to handle this that is JSON API compliant?\r\nShould I handle this use case separately and add it to our version of the JSON API spec?\r\n\r\nThanks for reading,\r\nAndrew Toy"}}
{"actor":{"display_login":"ethanresnick"}}