I've been trying to set up an API Controller in Umbraco 7.2.1, but I'm having issues getting it to recognize the default routes.
This is my controller:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Web;
using System.Web.Http;
using Umbraco.Web.WebApi;
using MyProject.Models;
using MyProject.Models.Repositories;
namespace MyProject.Controllers.Api
{
public class BookingsController : UmbracoApiController
{
BookingsRepository repository;
public BookingsController()
{
repository = new BookingsRepository();
}
[HttpGet]
public HttpResponseMessage Index()
{
try
{
return Request.CreateResponse(HttpStatusCode.OK, repository.GetAllBookings(), "application/json");
}
catch (Exception e)
{
return Request.CreateResponse(HttpStatusCode.InternalServerError, (object)null, "application/json");
}
}
}
}
The problem is that neither the HTTP methods nor the action names can be implicitly resolved.
I expected to be able to reach the Index action by using "/umbraco/api/bookings" but it doesn't seem to be mapped.
If I try to call "/umbraco/api/bookings/index" it maps correctly but required me to explicitly annotate the action with [HttpGet] otherwise it will tell me GET is not allowed.
It does not look like a default action is mapped. See the source for how I think the routes are for the API. Not sure how you add your own routes since I have not had to use it yet. Interesting on the [HttpGet], I would find that a bit frustrating if that is the case.
Umbraco 7 API Controller - Default Routing Issue
Hi,
I've been trying to set up an API Controller in Umbraco 7.2.1, but I'm having issues getting it to recognize the default routes.
This is my controller:
The problem is that neither the HTTP methods nor the action names can be implicitly resolved.
I expected to be able to reach the Index action by using "/umbraco/api/bookings" but it doesn't seem to be mapped.
If I try to call "/umbraco/api/bookings/index" it maps correctly but required me to explicitly annotate the action with [HttpGet] otherwise it will tell me GET is not allowed.
Thanks in advance.
It does not look like a default action is mapped. See the source for how I think the routes are for the API. Not sure how you add your own routes since I have not had to use it yet. Interesting on the [HttpGet], I would find that a bit frustrating if that is the case.
is working on a reply...