Created
June 21, 2012 12:26
-
-
Save tugberkugurlu/2965468 to your computer and use it in GitHub Desktop.
Running conneg manually inside a controller - ASP.NET Web API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CarsController : ApiController { | |
public string[] Get() { | |
var cars = new string[] { | |
"Car 1", | |
"Car 2", | |
"Car 3" | |
}; | |
var contentNegotiator = Configuration.Services.GetContentNegotiator(); | |
var connegResult = contentNegotiator.Negotiate(typeof(string[]), Request, Configuration.Formatters); | |
//you have the proper formatter for your request in your hand | |
var properFormatter = connegResult.Formatter; | |
//you have the proper MediaType for your request in your hand | |
var properMediaType = connegResult.MediaType; | |
return cars; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment