How to format response data in ASP.NET Core

Take advantage of FormatFilterAttribute in ASP.NET Core to format response data based on the request URL

How to format response data in ASP.NET Core
Simon Carter / Getty

ASP.NET Core provides excellent support for formatting data, whether it’s output data or data in the request body. When working in ASP.NET Core, your API methods will typically return JSON data, but you can also return data in formats other than JSON such as XML.

For example, a call to /api/default.json should return data from the API method in JSON format, whereas a call to /api/default.xml should return the data in XML format. In this article, we’ll look at how we can control the format in which data will be returned from ASP.NET Core based on the extension of the URL.

To work with the code examples provided in this article, you should have Visual Studio 2019 installed in your system. If you don’t already have a copy, you can download Visual Studio 2019 here.  

Create an ASP.NET Core API project

To continue reading this article register now