Problem/Motivation
Would it be possible to provide an action plugin so that the power of this module becomes accessible from the Drupal UI or for other modules like e.g. ECA or Views Bulk Operations?
Proposed resolution
Such a plugin would require a configuration form which allows the selection of the http request service from a drop down list and a text field, where the arguments for the request could be configured in e.g. YAML format by also supporting tokens. Something like that would be really powerful and I could provide an MR, if maintainers were interested.
Note: this request was triggered by #3316178: Action to send data to external API
Issue fork http_client_manager-3316197
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 3316197-provide-an-action
changes, plain diff MR !3
Comments
Comment #2
aronne commentedHi @jurgenhaas,
I just read your feature request and it sounds like a really cool request. If you're already working on that and wanna open a MR please do. I'll be happy to try it out and add it to the module.
Thanks again,
aronne
Comment #3
jurgenhaasThanks @aronne for your quick response. I'm happy to get this started, just wondering if this module provides any services that gives me access to all available services with their commands and parameters. And if I understand correctly, there can also be pre-configured requests? If that's correct, would be nice to get a list of those too.
Comment #4
amal.bukhari commentedI'm more of an end user and I'll be happy to help in use cases.
Also very helpful if the client manager can catch error codes and make them accessible as tokens for later use elsewhere (say, in ECA, VBO etc.), such that end users can perform necessary actions after catching error the codes.
Comment #5
aronne commentedHi @jurgenhaas and @amal.bukhari
Services API list
you can use the http_client_manager.http_services_api service to get a list of all the available services API.
eg:
\Drupal::service('http_client_manager.http_services_api')->getServicesApi()You can find an example usage here: https://git.drupalcode.org/project/http_client_manager/-/blob/9.3.x/src/...
Services API Commands list
Also, you can get a list of all the Service API Commands in that way:
Another example usage: https://git.drupalcode.org/project/http_client_manager/-/blob/9.3.x/src/...
Error handling
You can either use a try catch:
or use an HTTP Service API Wrapper as explained here https://www.drupal.org/docs/contributed-modules/http-client-manager/http... and override the basic implementation of the logError method:
Preconfigured requests
You can create them for every command defined in you http services api. https://www.drupal.org/docs/8/modules/http-client-manager/http-config-re...
You can list them all by using the entity_type.manager service, since they are ConfigEntities.
Hope it helps!
Comment #7
jurgenhaasPlease have a look at the initial implementation. Here is what it creates:
What's not yet included is the error handling and storage of the result. The problem with the latter: regular actions do not have access to ECA's token system, that's only available, if we implement this as an ECA integration, but then ECA would become a dependency of this module, what's certainly not desirable. Instead, we could store the result in the expirable key/value store?
Comment #8
aronne commentedI took a look at your implementation and I really like it. About the storing of results I agree with you on using the expirable key_value storage or even the StateApi.
You could try and go ahead with the expirable key_value and see how it goes.
Comment #9
jurgenhaasI've now implemented the storage into the expirable key value store as well. Seems to be working just fine.
What I've noticed during testing, both for commands and for preconfigured requests, the integer arguments are throwing exceptions in PHP 8.1 because Drupal provides them as strings. I guess, you would have to go through all the command arguments and cast the strings to integer, when they are of that type. This is off-topic here but I thought I'll capture it.
Comment #10
aronne commentedYes I know @jurgenhaas
for now don't care about that bug. I'm gonna work on it in a separate issue tomorrow.
Comment #11
jurgenhaas@aronne wondering if you had a chance to move this one forward? Asking because it may well be that we gonna have a client project where this would become very interesting soon.
Comment #12
aronne commentedHi @jurgenhaas
I'm working on this issue #3323767: Add a data integrity layer which should fix the problem you raised.
It should be available soon.
Comment #13
aronne commentedHi @jurgenhaas,
could you try and apply the patch I provided on the following issue? #3323767: Add a data integrity layer
Let me know if it works for you together with your implementation.
Comment #15
aronne commentedAvailable @dev version
Comment #16
jurgenhaasThis is great news, thanks @aronne
I wonder, if you wanted to add "ECA: Event - Condition - Action" as an eco-system into the project page of your module? It would then automatically show up in the list of modules that integrate with ECA.
Comment #17
aronne commentedYes of course! done ;)
Comment #18
jurgenhaasAmazing, thank you so much. Already announced your integration in our ECA slack channel.