0

I've built a REST API using flask and marshmallow. Now I'm wanting to show data in a table on the client side (I'm using vuejs).

The JSON from the API contains related objects like so:

json
{ match: 1,
  date: 2017-12-12,
  player: { name: "Juan", number: 1} }

I can't push this info directly into a table. I'm looking for best practice: provide arg on API for flattened 'table ready' JSON, or just rework the data before adding to table, or other?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
gotchula
  • 171
  • 1
  • 4
  • 1
    It isn't really clear what you are asking here. The various directives in Vue would have no trouble dealing with JSON like this and formatting it into a table. What trouble are you having that leads to the conclusion that you can't put this into a table? What have you tried? – Mark Jun 18 '17 at 22:09
  • 1
    I think it's reasonably clear. He is asking whether he should retrieve JSON from the server without nested objects, or de-nest them client side. FWIW I don't think there is a good answer. For one, it's probably premature optimization and whichever way is easiest will be best. Client side this is a straight up computed value. Server side, no idea. – Bert Jun 19 '17 at 03:11
  • yeah basically i was wondering if there was a _duh the correct way is x and here's why_ . Since i'm creating both the server and client side i'm not constrained. – gotchula Jun 19 '17 at 06:45
  • 1
    Ah, I see. I think it's a matter of opinion. My opinion is that the JSON data represents the model and probably shouldn't care or know about how it will be displayed - leave that up to the view layer, which is more than capable of dealing with it. Maybe there's middle ground where the JSON can be more convenient while still being a good representation of the data. – Mark Jun 19 '17 at 07:06

0 Answers0