Copied to clipboard

Flag this post as spam?

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


  • Dan Sørensen 102 posts 327 karma points
    Feb 12, 2014 @ 16:44
    Dan Sørensen
    0

    web api

    Hello umbraco people im a little stuck with making an web api. I have made this short peace of code just for a test. But when I make a get to http://www.domain.dk/Umbraco/Api/TestApiController/giveId
    It dosent work.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using Umbraco.Web.WebApi;
    
    namespace test.Controllers
    {
    public class TestApiController : UmbracoApiController
    {
    
        public int multiplyingTwoNumbers(int firstNumber, int secoundNumber)
        {
            int multiplyingResult = firstNumber * secoundNumber;
            return multiplyingResult;
        }
    
        public int giveId()
        {
            int id = 1;
            return id;
        }
    }
    
    }
    
  • Jeroen Breuer 4860 posts 12121 karma points MVP 3x admin c-trib
    Feb 13, 2014 @ 12:07
    Jeroen Breuer
    0

    Hello,

    Try removing Controller from TestApiController to see if it works. More info here: http://our.umbraco.org/documentation/Reference/WebApi/

    Jeroen

     

  • Dan Sørensen 102 posts 327 karma points
    Feb 13, 2014 @ 13:07
    Dan Sørensen
    0

    I uploaded it to the server then it worked. so I cant call the api frem localhost ?

  • Jeroen Breuer 4860 posts 12121 karma points MVP 3x admin c-trib
    Feb 13, 2014 @ 13:13
    Jeroen Breuer
    100

    You should be able to call the api from localhost. Just change the url to start with your localhost. Please mark a post as the answer if it helped you.

    Jeroen

  • antao 81 posts 371 karma points
    Feb 13, 2014 @ 13:45
    antao
    0

    Hi Dan, 

    You can even use these tools (fiddler is one of my best friends) to test it, localy or on other enviroments.

    http://www.telerik.com/fiddler

    https://chrome.google.com/webstore/detail/advanced-rest-client/hgmloofddffdnphfgcellkdfbfbjeloo

     

  • Dan Sørensen 102 posts 327 karma points
    Feb 18, 2014 @ 09:43
    Dan Sørensen
    0

    Normaly I would use Postman to test my web api, looks a little like the last one you are referring to antao And Jeroen sure I tried this but it dident give me any answers back. And thanks for all your replies

  • Anthony Barsotti 26 posts 66 karma points
    Jun 11, 2015 @ 19:07
    Anthony Barsotti
    0

    I'm having a similar issue, I've added a Controllers directory to the root of my project and placed a controller called CallsController.cs in that directory. The code for that is as follows:

    using System.Collections.Generic;
    using Umbraco.Web.WebApi;
    
    namespace CallsAPIControllerProject.Controllers
    {
        public class CallsController : UmbracoApiController
        {
           public IEnumerable<string> Test()
            {
                return new[] { "Table", "Chair", "Desk", "Computer", "Beer fridge" };
            }
        }
    }
    

    If I submit a GET request to ~/Umbraco/Api/Calls/Test/ it returns a Page Not Found error. Am I supposed to be placing the controller somewhere else?

  • Bjarne Fyrstenborg 1140 posts 3225 karma points MVP 3x c-trib
    Jun 11, 2015 @ 19:27
    Bjarne Fyrstenborg
    0

    Hi Anthony

    When you have wrapped the ApiController inside a namespace do you then see it in the /bin folder? ... I think the file may be called CallsAPIControllerProject.dll in your case.

    If it isn't there you should add the reference and build the project... if that doesn't work then maybe try to change the namespace to CallsAPIControllerProject.ApiControllers or something else without the ".Controllers".

    /Bjarne

  • Anthony Barsotti 26 posts 66 karma points
    Jun 11, 2015 @ 20:38
    Anthony Barsotti
    0

    I just moved the controller to the App_Code directory and it works now, thanks!

Please Sign in or register to post replies

Write your reply to:

Draft