Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[HttpClient] add ResponseInterface::toArray()#30499

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

@nicolas-grekas
Copy link
Member

QA
Branch?master
Bug fix?no
New feature?yes
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed tickets-
LicenseMIT
Doc PR-

I'd like we discuss adding atoArray() method toResponseInterface.

JSON responses are so common when doing server-side requests that this may help remove boilerplate - especially the logic dealing with errors.

WDYT?

(about flags, I don't think we should make them configurable: if one really needs to deal with custom flags, there's alwaysResponseInterface::getContent() - but it should be very rare.).

}

if (!\is_array($content)) {
thrownewJsonException(sprintf('Response returned %s while an array was expected.',\gettype($content)));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

quoted %s

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

updated to:
JSON content was expected to decode to an array, %s returned.

publicfunctiongetContent(bool$throw =true):string;

/**
* Gets the response body decoded as array, typically from a JSON payload.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

does this mean component will deal with e.g. XML if requested? What if ppl want to leverage a serializer for this?

Honestly, do want the API? :D

From#30502

ppl can always encode/decode on their own if they really want precise control on these

yet, we kinda want this 30+ line method :) should it be util instead?

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Integration with Serializer should be provided by decoration.

Copy link
MemberAuthor

@nicolas-grekasnicolas-grekasMar 9, 2019
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Note I see no reasons why integration with Serializer should implementHttpClientInterface: turning strings (even when coming from response bodies) to objects is not the domain of an http client to me.

Copy link
Contributor

@ro0NLro0NLMar 9, 2019
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

In that case i think we need to update the description to something likeGets a decoded body array representation (typically ...).

Let's say i decorate this toArray to mutate data, but im passing this client globally around in my app; some services might be effected by this.

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

🤔 I'm not sure to spot the difference, semantically :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Missed your comment, you're right we can expect HTTP domain; thus the body decoded as-is.

👍 with a simple decoration solution for extension in the future.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

that would also help#30494 btw

@nicolas-grekasnicolas-grekas merged commitaabd1d4 intosymfony:masterMar 10, 2019
nicolas-grekas added a commit that referenced this pull requestMar 10, 2019
…-grekas)This PR was merged into the 4.3-dev branch.Discussion----------[HttpClient] add ResponseInterface::toArray()| Q             | A| ------------- | ---| Branch?       | master| Bug fix?      | no| New feature?  | yes| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets | -| License       | MIT| Doc PR        | -I'd like we discuss adding a `toArray()` method to `ResponseInterface`.JSON responses are so common when doing server-side requests that this may help remove boilerplate - especially the logic dealing with errors.WDYT?(about flags, I don't think we should make them configurable: if one really needs to deal with custom flags, there's always `ResponseInterface::getContent()` - but it should be very rare.).Commits-------aabd1d4 [HttpClient] add ResponseInterface::toArray()
@nicolas-grekasnicolas-grekas deleted the hc-response-toarray branchMarch 10, 2019 17:26
@nicolas-grekasnicolas-grekas modified the milestones:next,4.3Apr 30, 2019
@fabpotfabpot mentioned this pull requestMay 9, 2019
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@fabpotfabpotfabpot approved these changes

+1 more reviewer

@ro0NLro0NLro0NL left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

4.3

Development

Successfully merging this pull request may close these issues.

5 participants

@nicolas-grekas@fabpot@ro0NL@ogizanagi@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp