Reputation: 3459
If I have a website with a REST API sending data to populate graphs on a front end, and I want to have one of the graphs click to send you to a new page with more data about that specific point, what is the RESTful way to do this?
If I use the html header to set up the new page with localhost/scatter_plot
where i select a day to look at from a clickdown, then I click an item on the scatter plot, I'm imagining it can redirect me to a page like localhost/single_item/123
for more information on that item, but would I use the 123
to trigger an API call to populate the graph on that item?
This seems convoluted and I was wondering what the optimal technique is for this sort of page navigation.
Upvotes: 0
Views: 717
Reputation: 57239
If I have a website with a REST API sending data to populate graphs on a front end, and I want to have one of the graphs click to send you to a new page with more data about that specific point, what is the RESTful way to do this?
Include descriptions of the hypermedia controls in the data that you send to populate the graph.
That is to say, update the definition of your media type for the graph data so that you can include zero or more hypermedia controls (aka "links") in the data. Each datapoint, in addition to the values used to graph it, would have a place to put the control (the url, and the semantic meta data). Clients that recognize the controls would expected to make them part of the presentation, as appropriate.
A JSON representation might look something like
"points" : [
{
"xPos" : 15,
"yPos" : 0,
"label" : "July 15, 2016"
"links" : [
{ "rel" : "details"
, "href": "..."
},
// more links if necessary
]
},
// more points
]
Typically, the client would be expected to know the different kinds of relations in advance (this is analogous to the browser knowing how to parse A and IMG correctly, without knowing ahead of time what value will be in href), and to ignore relations that it doesn't understand (allowing you to add more links in your api without breaking existing clients).
Upvotes: 1