Skip to content

Response when updating attributes of resource not conform spec #577

Closed
@maurei

Description

@maurei

The specs for updating a resource state:

200 OK
If a server accepts an update but also changes the resource(s) in ways other than those specified by the request (for example, updating the updated-at attribute or a computed sha), it MUST return a 200 OK response. The response document MUST include a representation of the updated resource(s) as if a GET request was made to the request URL.

A server MUST return a 200 OK status code if an update is successful, the client’s current attributes remain up to date, and the server responds only with top-level meta data. In this case the server MUST NOT include a representation of the updated resource(s).

JsonApiDotNetCore does not comply with the piece in bold text. Currently, after an update the response for the update pipeline always returns a full representation of the resource on the server.

In the default implementation of the pipelines, how a resource will change will always be fully specified by the request, in which case the server must never return an updated representation.

Users can easily add business logic that introduces additional changes, and only in this case the server must return an updated representation.

Implementing this part of the spec is challenging because it is nearly impossible for JADNC to detect if the business logic as introduced by the developer does anything like this. Hence it would probably be a more feasible approach to create a service that is responsible for signalling this to the internals of the framework. Such service would then explicitly be called by the developer.

Perhaps this issue can be tackled together with #536.
Eg we could introduce a helper service to take care of updates other than those specified by the request

updatedArticle.updatedAt = DateTime.Now();
_updateHelper.MarkAsUpdated(a => a.updatedAt);

the _updateHelper can then signal this to the repository layer which would solve #536, as well as to the serialization layer which would solve the current issue. This way we wont have to clutter the interface of the repository layer and could custom serialization layer opt out on such signal.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions