I have the following remainder scheme that I would like to implement using ASP.NET Web Api:
http:
http:
http:
http:
My first two links work correctly using ApiController and the following two methods:
public class StudentsController : ApiController {
public IEnumerable<Student> GetStudents() {
}
public IEnumerable<Student> GetStudent(string id) {
}
}
In the same controller (or do I need another controller called ClassesController?), How would I implement the last two links? In addition, what does routing look like for some classes (if necessary)?
Here is my WebApiConfig (which I would like to save as a dynamic rather than hard-coding route to / classes, if possible:
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
context.Routes.MapHttpRoute(
name: "JobsApi",
routeTemplate: this.AreaName + "/Students/{id}/Classes/{classId}",
defaults: new { classId = RouteParameter.Optional }
);
EDIT Here is my newly created ClassesController:
public class ClassesController : ApiController {
public IEnumerable<TheClass> Get(string id) {
return null;
}
}
I get 404 errors when trying to go to this url:
http://mydomain/api/students/s123/classes
source
share