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

FEAT Always return representation after write operation #78

Merged
merged 3 commits into from
Oct 8, 2024

Conversation

toopay
Copy link
Member

@toopay toopay commented Oct 8, 2024

Description

This PR modifies the behavior of write operations in the system to ensure that a representation of the affected resource is always returned after a write operation (such as POST, PUT, or PATCH).

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Further comments

Returning a representation after a write operation aligns with common RESTful API practices and provides several benefits:

Immediate Feedback: After a resource is created, updated, or modified, the client needs confirmation of the result. Returning the updated resource provides immediate feedback to confirm that the operation was successful and how the resource looks after the change.

Reduced API Calls: By returning the resource immediately, the client does not need to make an additional GET request to retrieve the updated representation, reducing the number of API calls and improving efficiency.

Data Integrity Verification: Returning the resource enables the client to verify the integrity and consistency of the data after the write operation, ensuring that all fields are properly updated and no data is lost or modified incorrectly.

Standards Compliance: This approach follows REST principles, particularly the best practice of returning the new state of the resource after modifying it. For example, after a POST request to create a new resource, the API should return the newly created resource with all relevant fields (e.g., auto-generated ID or timestamps). Similarly, after a PUT or PATCH, the updated resource should be returned.

Copy link

codecov bot commented Oct 8, 2024

Codecov Report

Attention: Patch coverage is 0% with 7 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
controller.go 0.00% 3 Missing ⚠️
pkg/db/relation.go 0.00% 3 Missing ⚠️
pkg/db/select.go 0.00% 1 Missing ⚠️
Flag Coverage Δ
-race 72.22% <0.00%> (-0.02%) ⬇️
-tags "sonic avx" 72.19% <0.00%> (-0.03%) ⬇️
-tags go_json 72.19% <0.00%> (-0.04%) ⬇️
-tags nomsgpack 72.19% <0.00%> (+0.04%) ⬆️
go-1.21 71.50% <0.00%> (-0.06%) ⬇️
go-1.22 72.22% <0.00%> (+0.02%) ⬆️
macos-latest 72.21% <0.00%> (-0.04%) ⬇️
ubuntu-latest 72.24% <0.00%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
pkg/db/select.go 88.88% <0.00%> (ø)
controller.go 58.92% <0.00%> (-0.54%) ⬇️
pkg/db/relation.go 71.81% <0.00%> (ø)

@toopay toopay merged commit 1516ea6 into main Oct 8, 2024
24 of 25 checks passed
@toopay toopay deleted the feature/return-representation-on-write branch October 8, 2024 04:27
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