Question

I need to build a web API on an existing umbraco website. A search on google ended up here.

Perhaps the only one blog in entire web, that handle this topic. But its a little vague one, Its not easy to understand what blogger actually means. So can any one else show me some other resources where i need to look in to or perhaps explain to me what actually i need to do?

Was it helpful?

Solution

I've created a web api project that sits between an Umbraco v4 website & other websites that want to be able to get information that is content managed in the original website. Add a /base class to the original website (http://our.umbraco.org/wiki/reference/umbraco-base) this will allow you to extract information from the umbraco nodes by calling the base methods from a web api project. One gotcha is that if you return a node through base any content or media pickers will be represented by the node number picked - so you will have to expand this into a URL (usually) before passing back to the web api.

In Umbraco v6 this functionality is much simpler as the is a built in contentservice api (http://umbraco.com/follow-us/blog-archive/2013/1/22/introducing-contentservice-aka-the-v6-api.aspx).

OTHER TIPS

I have used Web API alongside an Umbraco 4.11 installation without issues in the past. This involved setting up a startup handler (instead of using Global.asax) to hook web api configuration to Umbraco:

public class WebApiStartupHandler : IApplicationEventHandler
{
    public void OnApplicationInitialized(UmbracoApplication httpApplication, ApplicationContext applicationContext) {}

    public void OnApplicationStarting(UmbracoApplication httpApplication, ApplicationContext applicationContext) {}

    public void OnApplicationStarted(UmbracoApplication httpApplication, ApplicationContext applicationContext)
    {
        WebApiConfig.Register(GlobalConfiguration.Configuration);
        RouteConfig.RegisterRoutes(RouteTable.Routes);
        FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);  
    }
}

I think that 4.7 had probably a different way to do this, inheriting from a class instead of implementing an interface, but the general idea was the same.

I also had to add the url segment used for the api (e.g. ~/api) to the list in the web.config appSettings field named umbracoReservedUrls.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top