1

I'm trying to get a test application running using MVC WEB API but i can't get it work. What i want to do is send a GET request and as an answer get log records from a database as response.

Here's what i've set up:

Global.asax.cs: (unmodified)

  public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapHttpRoute(
            name: "DefaultApi",
            routeTemplate: "api/{controller}/{id}",
            defaults: new { id = RouteParameter.Optional }
        );

        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
        );
    }

my controller is called DBModelController:

 public class DBModelController : ApiController
{
    public IEnumerable<Log> GetAllLogs()
    {
        IDBModel DAO = new DBModelDAO();

        IList<Log> Logs = DAO.GetLogs(DateTime.Now, DateTime.Now); //this gives back Log objects

        return Logs;
    }

}

and how i want it to use:

http://localhost:15339/api/logs --and in return i get back a set of serialized records

thank you very much in advance

2 Answers 2

2

Change your class to LogsController

Sign up to request clarification or add additional context in comments.

Comments

1

Create a new route if you are not interested to change the controller class name into Logs.

routes.MapHttpRoute(
    name: "log_route",
    routeTemplate: "api/logs",
    defaults: new { controller = "DBModel", action = "GetAllLogs" }
);

This route should be placed before the default routes.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.