Base solution for your next web application
Open Closed

Add Custom WebApi Controller #148


User avatar
0
saraya created

Hi, I need to add custom WebApi to manage Output Cache and etc ... How can I do this ? adding to current webapi project or add new webapi project to abp solution ?


7 Answer(s)
  • User Avatar
    0
    hikalkan created
    Support Team

    Hi,

    You can add custom WebAPI controllers to current WebApi project. Purpose of this project is that.

  • User Avatar
    0
    saraya created

    Hi Hikalkan, Thanks for your reply, but still i'm confused which interface or class should be inherit because it is just a class library , could you send me or show me a sample code ? and could I host a Web Api project on separate server?

  • User Avatar
    0
    hikalkan created
    Support Team

    Hi,

    Startup template configured to run all web APIs in .WebApi project including custom ones. You can inherit from AbpApiController. But it will work if you even derive from standard ApiController. Just create a simple api controller and try it. If can want to host in a seperate server, then you should configure it to work in IIS or a Windows Service. These are not special to ABP, just regular Web API stuff. I believe you can find many resources if you search web. After implementing it, if you have a problem, you can always write here.

  • User Avatar
    0
    twinnn created

    Hi,

    I've added custom api controller with one method(inherited from abpapicontroller). Please, how can I call this method via HTTP? Do I need to register that controller or route? When I try to call this method using app/{apicontroller}/{method} I'm getting following error (route included):

    • message: No HTTP resource was found that matches the request URI 'http://localhost:6234/api/photos/upload'.
    • messageDetail: No type was found that matches the controller named 'photos'.

    Thank you in advance

    Regards Peter

  • User Avatar
    0
    hikalkan created
    Support Team

    If your ApiController normally works, it should also work for ABP since there is no special thing for regular web api controllers. I create one in .WebApi project:

    public class ProductController : AbpApiController
        {
            [HttpGet]
            public virtual IEnumerable<Product> GetProducts()
            {
                return new List<Product>
                {
                    new Product {Name = "Monitor"},
                    new Product {Name = "CPU"}
                };
            }
            public class Product
            {
                public string Name { get; set; }
            }
        }
    

    And entered URL: <a class="postlink" href="http://localhost:6234/api/Product">http://localhost:6234/api/Product</a>

    This is the result, as expected:

    [{"name":"Monitor"},{"name":"CPU"}]
    

    I could not see any problem.

  • User Avatar
    0
    priteshsanipara created

    I am also have the same issue. Swagger shows all the dynamic api but not showing the API from controller inside webapi project

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Did you fix it ? If not, can you share your controller definition ?

    Thanks.