Base solution for your next web application
Open Closed

Custom API controller / Swagger #5609


User avatar
0
statuscast created

Hi,

We are using the DotNetCore MVC/jQuery solution..

We find that having all our API calls only be accessible via the path domain.com/api/services/app/Component/Method very inconvenient for our customers. We also realize that as most the API calls are dynamically generated from our AppServices, we are kind of locked in to this.

Since the actual API set we want to expose is fairly small, what we would like to do as a work around, so our customers can simply access the api from domain.com/api/Component/Method is create a small WebApi proxy layer that literally acts as a 100% passthru to the subset of AppService Api calls. My question is 3 fold:

  1. what project do we implement this so that these WebAPI calls will be accessible within both the MVc and the Host proect

  2. How do we set a custom route for these calls? I can't seem to get custom routes working in any Abp or AspNetZero projects

  3. How do we ensure these calls are included in our Swagger UI?

Also, if there are already some example of custom non-AppService API's being exposed like this, I could probably figure this out, happy to be pointed to the right area if I'm just missing it...

thanks! jasen


6 Answer(s)
  • User Avatar
    0
    aaron created
    Support Team

    Related issue with workaround: aspnetboilerplate/aspnetboilerplate#3082

    1. what project do we implement this so that these WebAPI calls will be accessible within both the MVc and the Host proect

    Web.Core project.

    1. How do we set a custom route for these calls? I can't seem to get custom routes working in any Abp or AspNetZero projects

    [Route("")] attribute.

    1. How do we ensure these calls are included in our Swagger UI?

    [RemoteService] attribute.

  • User Avatar
    0
    statuscast created

    Yes, I had seen that solution you suggested but didn't want to break the dynamic js api that is created so opted for a thin proxy layer. I will try this today, thank you.

  • User Avatar
    0
    ismcagdas created
    Support Team

    @statuscast any news ?

  • User Avatar
    0
    ismcagdas created
    Support Team

    Closing due to inactivty.

  • User Avatar
    0
    statuscast created

    I mentioned in e-mail I couldn't respond here until my password was reset, sorry it was still considered abandoned.

    The Route decorator worked fine as expected. We ended up using Swashbuckle and API versioning to give us a limited swagger file that we could publish as our API docs. So we have a "full" and "public" API now. The full is all inclusive and still includes all the ABP/AZ stuff. The "public" one is only showing API's that are decorated with GroupName="" We still unfortunately have to proxy out all our public API's that are dynamically generated, but it's not a huge deal. So, our proxy API looks something like this now:

    [ApiExplorerSettings(GroupName = "public")]
    [Route("/api/Components")]
    public  class ComponentsController : StatusCastControllerBase
    {
            private readonly IComponentsAppService _componentsAppService;
            public ComponentsController(IComponentsAppService componentAppService)
            {
                _componentsAppService = componentAppService;
            }
            
    		[HttpGet]
            [RemoteService(IsMetadataEnabled = true)]
            [Route("GetAll")]
            public async Task<PagedResultDto<Components.Dtos.GetComponentForView>> GetAll(Components.Dtos.GetAllComponentsInput input)
            {
                return await _componentsAppService.GetAll(input);
            }
    }
    
  • User Avatar
    0
    ismcagdas created
    Support Team

    @statuscast thanks a lot for sharing this with us. Can we close the topic ?