Closed
Description
Hi
I'm trying to get this working, and finding the documentation out of date compared to the current latest release (0.3.0-pre-2). I've tried looking directly at the sample app, but tagging hasn't been done for the 0.3.0 release so it's showing the latest refactorings and it's proving difficult to see where I'm going wrong.
I've included the nuget package (JSONAPI) into a web api project.
Heres my startup
public partial class Startup
{
public void Configuration(IAppBuilder app)
{
var config = new HttpConfiguration();
// Web API routes
config.MapHttpAttributeRoutes();
EnableCrossSiteRequests(config);
EnableJsonApiFormatting(config);
app.UseWebApi(config);
}
private static void EnableCrossSiteRequests(HttpConfiguration config)
{
var cors = new EnableCorsAttribute(
origins: "*",
headers: "*",
methods: "*");
config.EnableCors(cors);
}
private static void EnableJsonApiFormatting(HttpConfiguration config)
{
var formatters = config.Formatters;
var jsonFormatter = formatters.JsonFormatter;
var pluralizationService = new PluralizationService();
var formatter = new JSONAPI.Json.JsonApiFormatter(pluralizationService);
formatters.Add(formatter);
}
}
The Controller
public class ExamplesController : ApiController
{
[AllowAnonymous]
[HttpGet]
[Route("api/v1/examples/{id:int}")]
public Example Get(int id)
{
return DummyData.Examples.Get(id);
}
}
Model
public class Example
{
public int Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
}
I'm using postman (chrome extension) to do a GET request to my api
Content-Type: application/vnd.api+json
http://localhost:4444/api/v1/examples/1
and it's returning the raw object.
{
"id": 1,
"name": "example",
"description": "long example"
}
However on wiring in the JSONAPI it doesn't appear to do anything.
From the documentation I believe this is all I have to do to get it working.
What am I missing?
Metadata
Metadata
Assignees
Labels
No labels