fix(transport) #65: return HTTP 201 Created for newly created objects#195
Merged
lilgallon merged 2 commits intoIZIVIA:mainfrom Mar 27, 2026
Merged
Conversation
…bjects Adds an HttpStatusOverride coroutine context element that service implementations can use to signal object creation via signalObjectCreated(). The respond functions in HttpRequest.kt now check for this override, returning 201 instead of the default 200 when set. This is backward-compatible — existing behavior is unchanged unless the service explicitly calls signalObjectCreated(). Includes tests verifying both the 201 (new object) and 200 (update) cases.
lilgallon
reviewed
Mar 16, 2026
| .invertFromRequest(requestMessageRoutingHeaders) | ||
|
|
||
| httpRequest to runBlocking(requestMessageRoutingHeaders + responseMessageRoutingHeaders) { | ||
| httpRequest to runBlocking(requestMessageRoutingHeaders + responseMessageRoutingHeaders + HttpStatusOverride()) { |
Member
There was a problem hiding this comment.
Reminder for me: Add a release note stating that the callback provided to TransportServer.handle() must have HttpStatusOverride in its coroutine context to use signalObjectCreated
Member
|
Build fails, you should run |
lilgallon
requested changes
Mar 24, 2026
Member
lilgallon
left a comment
There was a problem hiding this comment.
Just a heads-up on our internal policy: AI tools are allowed as a development assistant, but using them for automated tasks (Git operations, bulk code generation, etc.) is not.
Could you remove the Claude reference from your commits? Thanks!
Signed-off-by: Rishabh Vaish <rishabhvaish.904@gmail.com>
4a834ad to
501e978
Compare
|
lilgallon
approved these changes
Mar 27, 2026
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.



The OCPI spec requires that PUT endpoints return HTTP 201 when a new object is created, and 200 when an existing object is updated (https://github.com/ocpi/ocpi/blob/v2.2.1-d2/status_codes.asciidoc). Right now the toolkit always returns 200 regardless.
I went with a coroutine context approach since it fits naturally with how the toolkit already handles
ResponseMessageRoutingHeadersandTokenHeader. The idea is:HttpStatusOverridecoroutine context element gets installed byTransportServerimplementations alongside the existing context elementssignalObjectCreated()when they determine the object is newrespondNullableObjectandrespondNullableListcheck for this override and return 201 if set, 200 otherwiseThis keeps everything backward-compatible — existing code doesn't change behavior at all. Only services that explicitly opt in by calling
signalObjectCreated()will see the 201 response.I also updated the test
Http4kTransportServerto install the context element and added tests covering both the creation (201) and update (200) paths.Fixes #65