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;
}
}
}
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.
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
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?
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".
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.
Hello,
Try removing Controller from TestApiController to see if it works. More info here: http://our.umbraco.org/documentation/Reference/WebApi/
Jeroen
I uploaded it to the server then it worked. so I cant call the api frem localhost ?
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
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
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
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:
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?
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
I just moved the controller to the App_Code directory and it works now, thanks!
is working on a reply...