Search code examples
asp.net-web-apiumbracoumbraco7

Create rest service Umbraco 7 backOffice


I read a lot on this issue. I read that I can use at web api asp.net to create rest service in Umbraco.

Can I create this api in Umbraco back office? If not, how do I connect the service to my local Umbraco site?

I can't find a simple tutorial that shows this.

EDIT:

I want to get Umbraco content data in client side.I read that I can create in server side(Umbraco) rest service that I can get data when I call to specific url to my Umbraco server.


Solution

  • Take a look at https://our.umbraco.org/DOCUMENTATION/Reference/WebApi/ - the article explains how to create controllers inheriting from UmbracoApiController.

    EDIT - I added this example:

    I made a controller like this:

    public class PartnersController : UmbracoApiController
    { 
        public IEnumerable GetPartners(string zip = "") { ... } 
    }
    

    Then I used jQuery and AngularJS like this:

    function getPartnersForZip($scope, $http) {
        $http({ method: 'GET', url: '/umbraco/api/partners/getpartners/?zip=' + getQueryVariable("zip") }).success(function (data) {
            $scope.partners = data;
        });
    }
    
    <div ng-controller="getPartnersForZip" ng-cloak>
        <ul class="dealer-list" ng-cloak>
            <li ng-repeat="partner in partners"></li>
        </ul>
    </div>
    

    This works for me. What have you tried?