Problem/Motivation
I'm creating an integration with an API-endpoint that can receive a json-payload in any structure. Meaning that the keys or properties depend on uri-variables. See https://developers.home-assistant.io/docs/api/rest/ (POST /api/services/{domain}/{service}) for more details. I'm aware of the json- and body-location types, but they both don't really apply.
Proposed resolution
There are 2 possible solutions:
- I add a new location type, Serializer and Deserializer and use those to create a new GuzzleClient in a decorated version of the Drupal\http_client_manager\HttpClient-class. This would remain private, in a separate module;
- Via a fork of this module, I create a new plugin type for locations, register the existing ones via
a deriverregular plugin classes, create a new one for this specific need (can be discussed whether it should be part of this module) and use the plugin manager when creating new instances of the default Serializer and Deserializer.
Remaining tasks
Decide on the path to take, to see if solution 2 would bring value to this module.
API changes
A new plugin type would be introduced.
Issue fork http_client_manager-3397521
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:
Comments
Comment #2
lammensj commentedComment #3
lammensj commentedComment #4
lammensj commentedComment #5
lammensj commentedI've created the mentioned plugin manager and added plugins for the existing locations that are already part of the Guzzle-package. Let me know what you think :)
Comment #6
aronne commentedHi @lammensj,
I took a look at your work and I really love what you've done.
I would avoid putting this implementation into a separate module, I prefer the 2nd option.
Tho we must be 100% sure this new implementation doesn't break already existing service descriptions so if you could add some tests it would be great!
Comment #7
lammensj commented@aronne, glad you approve!
I've added some unit-tests for the specific plugins that are included, based on the same unit tests as for the guzzle-service package itself: see https://github.com/guzzle/guzzle-services/tree/1.4.0/tests/RequestLocation. I've also updated the HttpClient-test by prophezing the plugin manager and injecting it. Is this sufficient?
Comment #8
aronne commentedHi @lammensj,
great job again, thank you.
Could you please open a MR or upload a patch so that we can go online with your feature?
Regards,
aronne
Comment #10
lammensj commentedPR for the general functionality is created.
What's your take on the additional RequestLocation-plugin for body-payloads without a key? Do you think it should be/can be included in this module or something a developer now might create itself?
Example: https://gist.github.com/lammensj/dca48a5bb9d8b659e1a79e8aaf380d4b
Comment #11
aronne commentedHi @lammensj,
I think you could add it directly in this module.
Comment #12
lammensj commented@aronne, I've added the extra plugin and a test to the PR.
Comment #14
aronne commentedHi @lammensj,
thank you for the great job you've done with this implementation.
I'm gonna create a new release soon.
Kind regards,
aronne