Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Emil Custic 1 post 21 karma points
    Dec 22, 2014 @ 12:54
    Emil Custic
    0

    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:

    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.

    Thanks in advance. 

  • Jerode 44 posts 159 karma points
    Dec 22, 2014 @ 20:27
    Jerode
    0

    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.

Please Sign in or register to post replies

Write your reply to:

Draft