joukevandermaas / saule

JSON API library for ASP.Net Web API 2.
https://joukevandermaas.github.io/saule
MIT License
76 stars 37 forks source link

Should not require Content-Type application/vnd.api+json for DELETE #146

Closed bjornharrtell closed 7 years ago

bjornharrtell commented 7 years ago
adamalesandro commented 7 years ago

@bjornharrtell I have a related type of issue. In our app we have one route that we would like to serve without requiring application/vnd.api+json Accept header. For my solution, I was thinking adding additional logic to ReturnsResourceAttribute to effectively turn off that requirement.

ReturnsResourceAttribute constructor:

public ReturnsResourceAttribute(Type resourceType, bool disableJsonApiFilter = false)

Usage:

[Route("api/attachments/{id}/download")]
[ReturnsResource(typeof(AttachmentResource), disableJsonApiFilter: true)]
public async Task<HttpResponseMessage> DownloadAttachment(int id)
{
...// etc.

While I don't expect that you would decorate all your DELETE actions this way, perhaps there is some common ground here. @joukevandermaas, curious if you've thought about this at all.

bjornharrtell commented 7 years ago

It's similar to https://github.com/joukevandermaas/saule/issues/100. I hope to be able to contribute a PR to fix it eventually.

joukevandermaas commented 7 years ago

@adamalesandro In my understanding, the spec says it's required if the client is talking to a JSON API server. There should be a way to 'turn off' Saule for specific endpoints, but then it should also turn off serialization IMO. I'm curious about your use-case, though.

@bjornharrtell I think Saule should not require the content-type header for any request without content (including DELETE of course), I think. At least, this makes sense to me :smile:

bjornharrtell commented 7 years ago

Agreed @joukevandermaas. I think @adamalesandro is also talking about requests without content.

adamalesandro commented 7 years ago

Yes, correct. In our case we want to return a file (as download) from an href link in an ember app.

adamalesandro commented 7 years ago

I should also add that I'm new to ember/JSON-API so if there's an already accepted way of serving files, I'd go that way. I have not come across anything viable from my research yet.

bjornharrtell commented 7 years ago

I was refering to posting (or patching) content to the server. Delivering content from the server anything else than application/vnd.api+json isn't JSON API, so I'd say Saule should not be involved - just make an ordinary Web API 2 controller.

bjornharrtell commented 7 years ago

@adamalesandro I see you are refering to both Accept and Content-Type headers which is confusing.

In my understanding the mime type for both should be application/vnd.api+json but is optional for requests/responses without body. A DELETE response may contain a body and in that case it will be a top level meta data for the deleted entities. See http://jsonapi.org/format/#crud-deleting.

adamalesandro commented 7 years ago

@bjornharrtell Well that's embarrassing. I was so caught up with how to make this work with saule, I never even thought of making a separate controller.

joukevandermaas commented 7 years ago

Fixed with #151.