-3

I have a backend Rails application that is mainly API endpoints and a front-end application that is mainly being built in React.

Consider the following models:

  1. Panel: is an container element inside a dashboard. It defines dimensions/positions inside the dashboard. It also defines its content using a content_type and a content_id (polymorphic associations).
  2. Chart / SingleValue / Section: these are all models that can be used as content for the panel.

What I would like to do now is letting the user create a "chart panel" in one step.

I've been wondering for a while now if it is better to:

  1. Have all the basic CRUD API end-points and manage the panel+chart creation 100% on the front-end. This would mean more complexity on the front-end but fewer API end-points.
  2. Have an extra API endpoint on the Rails side to create panel+chart/panel+single_value/panel+section (atomic operation). This would mean much less complexity on the front-end but more API end-points.

What would be the ideal approach?

Francesco Meli
  • 2,484
  • 2
  • 21
  • 52

2 Answers2

1

Maybe perform a single POST request to /panels/ for each panel creating with the following request body (Given that every panel needs a content):

{
  dimensions: '',
  positions: '',
  content: {
    type: 'chart', // singleValue, section
    // content attributes
  }
}

My suggestion is that Panel should be a centralized component (which parses dimensions and positions) and for each children you render them according content.type. You will be able to use a single endpoint and still keep RESTFul standards.

Hemerson Carlin
  • 7,354
  • 1
  • 27
  • 38
0

In my opinion, you can aggregate the granular endpoints and create more endpoints if it eases the complexity of the UI. This would basically be a Facade pattern(https://en.wikipedia.org/wiki/Facade_pattern) , where you would be aggregating the granular end points into specific higher order endpoints which would help the UI to create more complex structures without going into the implementation details of the said structures.

palsrealm
  • 5,083
  • 1
  • 20
  • 25