siren-js / api-browser

Siren API browser that uses Siren.js
https://siren-js.github.io/api-browser/
MIT License
2 stars 0 forks source link

Support for adhoc parameters on an action post #30

Open miller79 opened 1 year ago

miller79 commented 1 year ago

Sometimes the action is dynamic and unknown until you send the message. It would be good to be able to just add other parameters to send with the request if needed.

dillonredding commented 1 year ago

What do you mean by "the action is dynamic and unknown"? If an action isn't provided by the server, the client shouldn't be able to submit it.

miller79 commented 1 year ago

In a case we support an action but not quite sure all the inputs. For this service I'm working on, there's an action to be able to send a template with fields and it will generate a document. The issue is the fields in the document cannot be known ahead of time so the action only states how to load the document but cannot tell you anything else about it.

dillonredding commented 1 year ago

Very interesting use case. So, there is input, but the server doesn't know exactly what. Would it not know the fields from the template it's using? If not, how is the client supposed to know them if the server doesn't?

Domain aside, I'm not sure we should support adding arbitrary fields to an action. The server should be telling the client what it expects. Perhaps a special kind of action or field allows this, but I'm hesitant to support it for any action.

dillonredding commented 1 year ago

@miller79 What if we add support for a new field type that allows for a sequence of name-value pairs? The UI might look something like this, where the label is the field title (or name).

As for the field, the value could be a map of the name to values (the type being Record<string, string[]> where values are arrays to account for duplicate names). The question is then how are these serialized. We could provide a custom serializer, but this feels like something the underlying client library could/should support. So, I created an issue in that repo.

miller79 commented 1 year ago

Yeah that's pretty much exactly what I was hoping for.

dillonredding commented 1 year ago

Then we just need to figure out 1) the name of the field type, and 2) what request the server is expecting (something to discuss here).