Improve clarity of backend route composition
See original GitHub issueIs your feature request related to a problem? Please describe. If I start out a page with the following markup:
<Get path="/people">
{data => (
<Get path="/products" />
)}
</Get>
I find it unintuitive that the resulting backend path in the child Get
component is ${base}/people/products
, which, in an HTML analogy, would make more sense if I omitted the slash like in <Get path="products">
. It feels like an overhead to have to do ../products
in order to replicate the ‘absolute path’ behavior, or to pull in the backend URL again to set as base
prop. I wonder if we can make this more predictable.
Describe the solution you’d like The following code:
<Get path="/people">
{data => (
<Get path="/products" />
)}
</Get>
should make requests to ${base}/people
and ${base}/products
, whereas
<Get path="/people">
{data => (
<Get path="products" />
)}
</Get>
should make requests to ${base}/people
and ${base}/people/products
.
In this proposal, URL composition can be disabled by simply adding a slash. As a personal preference, I can even see myself forcing absolute paths at all times in order to remove coupling my components to the entire component hierarchy (and thereby making rearranging components risky). We could even enforce this as a kind of strict mode, or issue runtime warnings if the user opts into them.
Alternatives
I can foresee some confusion happening when relative and absolute positions are nested, but I’m sure we can figure out a nice set of rules on the implementation level. Maybe we can gather some data from projects using restful-react
- how much nesting/composition is desired and how nesting complexity is managed - to see what API makes the most sense.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:12 (9 by maintainers)
Top GitHub Comments
Hi @elangobharathi - sure, feel free to give it a go. It’ll be helpful to look at https://github.com/contiamo/restful-react/pull/33 to see all the things we’ve tried and discussed so far.
If @peterszerzo says so, absolutely. Welcome to the community. 🙂