Comments (6)
Actually the spec says that a POST should "contain an entity which describes the status of the request and refers to the new resource, and a Location header". Since there's no standard way to "describe the status of the request" using JSON, I opted to not try and include an entity in the response and simply use the Location header to point to the URL of the new resource.
If it's more convenient to return the newly-saved resource, then it wouldn't be that hard to do. IMO it's one of those gray areas where different server implementations create different expectations. My original thought was to save the bandwidth and not send a response entity back on POST because the user agent only needs to know if the save succeeded and the ID of the entity is the URI sent in the Location header.
from spring-data-rest.
Hin Jon,
okay got that. My expectations was, as you already mentioned, based on previous work with other implementations. The thing is, if I get 201 and the location to the object, that I won't try to merge the location into the object persisted and start another roundtrip getting the "whole" entity anyway.
But as you said, that is a matter of taste.
from spring-data-rest.
Riak has this behaviour but allows you to put a query parameter of "returnBody=true", which will return the entity you just created.
Would something like this work for you?
from spring-data-rest.
Jon,
I think this would be a solid way to go.
Great!
from spring-data-rest.
Just pushed a change (commit df8a891) to the POST method (of the entity, not of the relation/property POST) that accepts a query parameter of "returnBody=true" to return the JSON of the saved entity on a POST. By default, the behaviour is the same as currently (no body at all). Setting this query parameter to true will cause the entity to be rendered into the response, so you'll get a 201 and the entity representation.
from spring-data-rest.
Great!
from spring-data-rest.
Related Issues (20)
- Release 4.1.9 (2023.0.9)
- Release 4.2.3 (2023.1.3)
- PATCH request for updating nested collections does not work correctly since spring-boot 3.1.1 HOT 4
- Error "Couldn't find PersistentEntity for type class" when attempting to return Non-PersistenceEntity data HOT 1
- Augmenting arrays during merge patch only appends one element
- Nested arrays of entities need to get PUT semantics applied for merge patch
- Move off Expression infrastructure to apply JSON Patch paths
- Does spring data rest supports sorting on inherited fields? HOT 1
- Issue with Enum datatype in querydsl HOT 3
- Document how to use TestRestTemplate with spring-data-rest
- Release 4.1.10 (2023.0.10)
- Release 4.2.4 (2023.1.4)
- Release 4.3 M2 (2024.0.0)
- Json object not gettting captured in POST request HOT 4
- Upgrade to Spring Security 6.1.7 for integration tests
- Release 4.1.11 (2023.0.11)
- Release 4.2.5 (2023.1.5)
- Release 4.3 RC1 (2024.0.0)
- Upgrade to MongoDB driver 5
- Upgrade to Hibernate 6.5.0.CR1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from spring-data-rest.