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

Send 204 when WebAPI response contains no data #21349

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Piccirello
Copy link
Member

This change is part of a broader push to have the WebAPI send back semantically correct status codes.

https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/204

@Piccirello Piccirello added the WebAPI WebAPI-related issues/changes label Sep 16, 2024
@Piccirello Piccirello requested a review from a team September 16, 2024 21:05
@glassez glassez added this to the 5.1 milestone Sep 17, 2024
@glassez glassez requested a review from a team September 17, 2024 05:47
@@ -373,6 +373,9 @@ void WebApplication::doProcessRequest()
}
}
break;
case QMetaType::UnknownType:
Copy link
Member

Choose a reason for hiding this comment

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

what will trigger this case?

Copy link
Member

Choose a reason for hiding this comment

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

what will trigger this case?

Response w/o data.

Copy link
Member

Choose a reason for hiding this comment

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

Should all responses with no data use 204? Shouldn't it depend on what was requested?

Copy link
Member

Choose a reason for hiding this comment

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

Should all responses with no data use 204? Shouldn't it depend on what was requested?

I'm not sure I've understood the gist of your questions correctly...
In current architecture if "action" returns no data (i.e. it doesn't call setResult()) the data is of type QMetaType::UnknownType at this point so 204 status is sent in response.

Copy link
Member

@Chocobo1 Chocobo1 Sep 20, 2024

Choose a reason for hiding this comment

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

For example, setPreferencesAction() don't return data but is it expected for the client to receive 204 No Content in the response? Shouldn't the client expect it to be 200 OK?
I mean 204 probably should not be sent unconditionally and only some api should use it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Any request that doesn't result in data being sent back to the client should receive a 204. This page has useful information: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status.

Copy link
Member

Choose a reason for hiding this comment

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

I mean 204 probably should not be sent unconditionally and only some api should use it.

What's the point of it then?
What's the point of it then?
IIRC, it means the same as 200 but give the client a hint of that request processing can be optimized.

Shouldn't the client expect it to be 200 OK?

It should expect the code that is declared by API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
WebAPI WebAPI-related issues/changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants