I have created a web api which displays data from a table in database in json format. I want to create a nested api.
How can I do this?
My json when I call the api:
{
"ID":1,
"plVersion":1,
"mID":10,
"sID":1025,
"orID":null,
"x":22.9935,
"y":40.5885
}
I want something like this
[
{
"ID":1,
"header":{
"plVersion":1,
"mID":10,
"sID":1025
},
"mContainer":{
"aID":{
"orID":null
},
"Position":{
"x":22.9935,
"y":40.5885
}
}
}
]
My testController.cs
public class testController : ApiController
{
[Route("api/test")]
public IEnumerable<test> Get()
{
using (Raw_DataEntities entities = new Raw_DataEntities())
{
return entities.tests.ToList();
}
}
[Route("api/test/{id}")]
public test Get(int id)
{
using (Raw_DataEntities entities = new Raw_DataEntities())
{
return entities.tests.FirstOrDefault(e => e.ID == id);
}
}
}