Codit / practical-api-guidelines

Practical guidelines for building & designing APIs with .NET.
MIT License
16 stars 5 forks source link

Add guidelines about content negotiation #86

Open MassimoC opened 5 years ago

MassimoC commented 5 years ago

provide guidelines on content negotiation (accept / content-type).

MassimoC commented 5 years ago

Introduce ConsumesAttribute and ProducesAttribute

Having the operations decorated with these attributes should also affect the Swagger documentation.

For example:

[SwaggerResponse((int)HttpStatusCode.OK, "Player data object")]
[SwaggerResponse((int)HttpStatusCode.NotFound, "Player not found")]         
[SwaggerResponse((int)HttpStatusCode.InternalServerError, "API is not available")]
[Produces("application/json")]
public async Task<IActionResult> GetPlayer(int id) {}

What's the point to have application/json and text/json? We should remove text/json

fgheysels commented 5 years ago

Regarding text/json, application/json: I just took that over from the code at hand. Also to show how multiple contenttypes can be specified. But for me, it is OK to drop text/json.

MassimoC commented 5 years ago

Ref #102 and #103

tomkerkhove commented 5 years ago

@filipvanraemdonck is working on this. Pending invite to assign to him.