fix: API\ResponseTrait can't return string as JSON#8490
Merged
Conversation
a286a7d to
625628c
Compare
Member
|
Unless we will be able to parse the same JSON on the input, I think I will not be in favor. IMO we should support the same JSON parsing options for both: Request and Response. |
Member
Author
|
We can parse the string JSON $routes->post('/', 'Home::index');<?php
namespace App\Controllers;
class Home extends BaseController
{
public function index(): string
{
$json = $this->request->getJSON();
echo $json; exit;
}
}$ curl -H 'Content-Type: application/json' -d '"message"' localhost:8080/
message |
Member
|
Sorry, looks like I was mistaken. I thought we had a problem with that. |
michalsn
approved these changes
Feb 1, 2024
trampgeek
approved these changes
Feb 1, 2024
trampgeek
left a comment
There was a problem hiding this comment.
Looks good to me. Many thanks, Kenjis.
e686a30 to
f8b41ab
Compare
Member
Author
|
Added changelog and upgrade guide. |
f8b41ab to
cd2b2d2
Compare
PHP Deprecated: strtolower(): Passing null to parameter #1 ($string) of type string is deprecated
and will handle string data as JSON.
Test code should not set the conetnt type. ResponseTrait has the responsibility.
cd2b2d2 to
fac0fe2
Compare
This file contains hidden or 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
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.
Description
Fixes #8397
$this->respond()returnstext/html. But it should returnapplication/json.$this->respond()returnsapplication/json.$this->respond()returnsapplication/json.Before:
After:
Checklist: