Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Http Responses in the auto generated api controllers #513


User avatar
0
ofir1234 created

Hi. I have an application service called TrendsService. This service returns "normal" results like strings and ints. The problem is, I want sometimes to return a custom http-error (return a IHttpActionResult) from this service. I also want a method which returns a file to the client (which means I'm returning an HttpResponseMessage and fill it with a Stream Content). I know these things aren't related to the application level, but you have this automatic api-controller maker in ASP.Net Boilerplate. Does it have some flags to support such things ? (I know I can write [HttpGet] above a method in the service, but I need a little more than that. I need to return HTTP responses.) So, do you have any support for that or the only option is to create another controller which contains all the HTTP-related methods ? This makes my solution have two files : a TrendsController.cs and a TrendsService.cs which makes things look a bit messy.

Thanks


2 Answer(s)
  • User Avatar
    0
    ofir1234 created

    Bump. Still need an answer.

    Thanks.

  • User Avatar
    0
    hikalkan created
    Support Team

    You understood the system well, that's good :)

    Have you tried to add filters? You can add filters while creating auto web api.

    See this code for example: <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate-templates/blob/master/src/AbpCompanyName.AbpProjectName.WebApi/AbpProjectNameWebApiModule.cs#L16">https://github.com/aspnetboilerplate/as ... ule.cs#L16</a>

    You can use WithFilters method before Build().

    I don't know if filters can solve your problem, but I wanted to inform you about that. At least, this is the only available option for now.

    If it does not works, you can suggest a way to implement it in ABP (write to Gihbut issues please).

    Thanks.