Git Product home page Git Product logo

Comments (6)

jbrisbin avatar jbrisbin commented on August 19, 2024

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.

jhiemer avatar jhiemer commented on August 19, 2024

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.

jbrisbin avatar jbrisbin commented on August 19, 2024

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.

jhiemer avatar jhiemer commented on August 19, 2024

Jon,
I think this would be a solid way to go.

Great!

from spring-data-rest.

jbrisbin avatar jbrisbin commented on August 19, 2024

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.

jhiemer avatar jhiemer commented on August 19, 2024

Great!

from spring-data-rest.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.