Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

JSON API

[Route("api/Player/videos")]
public HttpResponseMessage GetVideoMappings()
{
    var model = new MyCarModel();
    return Request.CreateResponse(HttpStatusCode.OK,model,Configuration.Formatters.JsonFormatter);
}
//OR
[Route("api/Player/videos")]
public IHttpActionResult GetVideoMappings()
{
    var model = new MyCarModel();
    return Json(model);    
}
//If you want to change globally, 
//then first go to YourProject/App_Start/WebApiConfig.cs and add:
config.Formatters.XmlFormatter.SupportedMediaTypes.Remove(
config.Formatters.XmlFormatter.SupportedMediaTypes.FirstOrDefault(t => t.MediaType == "application/xml"));
//at the bottom of the Register method.
//Then try:
[Route("api/Player/videos")]
public IHttpActionResult GetVideoMappings()
{
    var model = new MyCarModel();
    return Ok(model);    
}
Source by jsonplaceholder.typicode.com #
 
PREVIOUS NEXT
Tagged: #JSON #API
ADD COMMENT
Topic
Name
7+3 =