Summary
Isn't that cool? The ability to change the format based on the Accept
header is very handy. This way, you are able to create a web API for many different clients – an API that accepts many different formats, depending on the clients' preferences. There are still many potential clients out there that don't use JSON and prefer XML or CSV.
The other way around would be an option to consume CSV or any other format inside the web API. For example, let's assume your client sends you a list of people in CSV format. How would you solve this? Parsing the string manually in the action
method would work, but it's not an easy option.
This is what ModelBinder
objects can do for us. Let's see how they work in the next chapter.