Skip to content
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

Introduce support to return 201 status code in Json Responses #291

Merged
merged 5 commits into from
Dec 21, 2022
Merged

Introduce support to return 201 status code in Json Responses #291

merged 5 commits into from
Dec 21, 2022

Conversation

denjaland
Copy link
Contributor

While refactoring our existing code from Laravel API resources to using Laravel Data, we noticed a lot of our tests were starting to fail, because we expect a 201 CREATED response code when we are creating a new resource.

I checked the Laravel codebase, and they return a 201 when $model->wasRecentlyCreated() equals true.
Obviously, the same check can not be done in this package, but I believe it would make sense to test for the request method, and if it is a POST request, we can have return the Json response with a 201 status code, which is what I implemented in this PR.

Obviously, in order to ensure backwards compatibility, I disabled this by default by adding a new config parameter that is y default set to false, but can be enabled in the config file, so this can be release as a minor and not a major.

@rubenvanassche
Copy link
Member

Hi @denjaland,

Thanks for the PR, I think this is more of a bugfix. So let's skip the whole config flag and do this by default! Could you make these changes? Thanks!

@denjaland
Copy link
Contributor Author

Will do. I'm always careful making backwards incompatible changes, but I agree it's a fix.

@denjaland
Copy link
Contributor Author

@rubenvanassche updated PR

@rubenvanassche rubenvanassche merged commit 687e7ff into spatie:main Dec 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants