-
Notifications
You must be signed in to change notification settings - Fork 183
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introducing the low-level API #324
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Codecov ReportAll modified lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## v2.x #324 +/- ##
============================================
+ Coverage 93.97% 95.32% +1.35%
- Complexity 362 365 +3
============================================
Files 27 27
Lines 1128 1134 +6
============================================
+ Hits 1060 1081 +21
+ Misses 68 53 -15
☔ View full report in Codecov by Sentry. |
Merged
@kbsali Any thoughts? |
kbsali
approved these changes
Oct 4, 2023
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hey 👋
This issue is more about a communication strategy than a technical issue.
I was thinking about #146 to implement a switch for JSON/XML responses.
The problem
Example: To change a project I run this code:
Because
Redmine\Api\Project::update()
uses the XML endpoint internally$response
is aSimpleXMLElement
instance and the response body contains XML as well, but I would like to have JSON:Workaround 1
The current workaround is to check for
SimpleXMLElement
and usejson_encode($response)
.Workaround 2
Another workaround could be to use
$client->requestPut()
directly to request the JSON endpoint:Now
$response
will be a JSON string. But this is not very intuitive, because now you have to know about the correct endpoints and handle JSON data withjson_encode()
andjson_decode()
again for the request instead on the response.New solution: Allow Serializers
So I came up with the idea to allow the public usage of the new serializer from #310 and #315. (The serializers are marked as
@internal
atm)The code from the first example could be look like this:
low-level API:
$client->request*()
+ SerializersTo switch between JSON or XML request/response by using the correct endpoint is already possible but requires more knowledge about the Redmine API, converting and sanitizing XML/JSON data and handling query parameters. The Serializer can simplify this.
For better communication I propose to call this the low-level API.
In this PR I started to point this out.
mid-level API:
$client->getApi()
In contrary the "normal" way of calling
$client->getApi('...')
will be called the mid-level API. The mid-level API is build on top of the low-level API.The mid-level API remains the recommended way to use php-redmine-api, but for special cases or missing features like #192 or #263 we can point to the low-level API as workaround.