L
L
LiptonOlolo2020-11-12 22:58:20
ASP.NET
LiptonOlolo, 2020-11-12 22:58:20

ASP.Net Core Web API uniform response format?

Actually the question is in the title.
What I want: a unified response format from the API like VK.
For successful results, the response format is approximately the following:

{
    "response": {
        "count": 2,
        "items": [
            1,
            2,
        ]
    }
}


And for errors, something like this format:
{
    "error": {
        "error_code": 5,
        "error_msg": "User authorization failed: invalid access_token (4)."
    }
}


I would like the responses to be formed on their own (so that I, for example, return IEnumerable from the controller, and the response is as above in the example), and not through the controller and the return type of the methods (public MyResponse<> Foo()).

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vasily Bannikov, 2020-11-13
@vabka

https://vmsdurano.com/asp-net-core-and-web-api-ac...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question