How I am using IActionConstraintFactory to handle content negotiation

Resource representation based on accept type

Rami Hamati
CodeX

--

Photo by Tierney in stock.adobe

I am assuming in this article that you already know what Rest and RestApi are, or if you are like me then you practice them, but it’s not easy to find the correct terminology to explain them.

I have to be frank, while I worked with API's pretty much in the last couple of years, and while I have read multiple articles (and watched multiple tutorials) regarding True Rest and HateOS, I haven’t actually worked with True Rest in practice…until now.

Why content negotiation? Because Rest resources can have multiple presentations depending on who is requesting that information. One can be the HR department, another one can be the Accounting department, and both would like different types of information regarding the same resource.

But, I am not going to write about content negotiation, but instead about how I am achieving that with IActionConstraintFactory , in order to have the same endpoint for the clients.

You can find a link to the demo using the following link: https://github.com/ramihamati/webapidemos/tree/main/WebApi.DemoActionConstraintFactory

Constraints

--

--

Rami Hamati
CodeX
Writer for

Software Engineer/Freelancer passionate about designing resilient, scalable and distributed systems. https://www.buymeacoffee.com/ramihamati