mui / toolpad

Toolpad: Full stack components and low-code builder for dashboards and internal apps.
https://mui.com/toolpad/
MIT License
1.27k stars 282 forks source link

Support custom function datasource #628

Closed Janpot closed 2 years ago

Janpot commented 2 years ago

The REST datasource is on a pathway of configuration bloat. There's just so many possible combinations of urls, path parameters, headers, query parameters, authentication, method, preprocessing, postprocessing, error handling,... as well as, no clear way to combine or chain requests.

We should allow the user to express their rest calls in plain javascript. e.g. allow the user to write queries of the form:

export default async function (input) {
  const response = await fetch(`https://dog.ceo/api/breed/${input.selectedBreed}/images/random`)
  if (response.ok) {
    return response.json()
  }
  throw new Error(`HTTP ${response.status}: ${response.statusText}`)
}

This would execute on the server and user will be presented with UI where they can define input to be passed from the page to the server function. The user would have full control over how urls are created, pre/post-processing, chaining multiple requests. Error handling,...

We can allow them to set up authentication headers per origin and have the server automatically use them when making requests.

We can also add a wizard that asks for a few basic parameters and generates the function code to start from.

This would make the following tickets obsolete:

benchmark:

Todo: evaluate methods of running untrusted code securely on the server side:

apedroferreira commented 2 years ago

+1, sounds like a great and important feature, it would also easily allow for a lot of integrations

apedroferreira commented 2 years ago

still, maybe having a simple, limited, non-bloated way of making REST requests wouldn't be bad either

prakhargupta1 commented 2 years ago

Interesting! As it has the potential to cover much of user's expectations around customization. It seems some WRITE use cases would also be possible through this.

Janpot commented 2 years ago

Sufficiently implemented by https://github.com/mui/mui-toolpad/pull/641 and follow-up PRs