Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ASP.NET Core usage style #65

Open
igorgiovannini opened this issue Mar 15, 2021 · 1 comment
Open

ASP.NET Core usage style #65

igorgiovannini opened this issue Mar 15, 2021 · 1 comment
Labels
question Further information is requested

Comments

@igorgiovannini
Copy link

igorgiovannini commented Mar 15, 2021

In our enterprise we are currently evaluating VTEX.

Having a look at the source code of this extension, I noticed you handle manually various stuffs for a specific endpoint (see https://github.com/vtex-apps/reviews-and-ratings/blob/master/dotnet/Controllers/RoutesController.cs).

Is there a technical need to handle the various cases manually, instead of taking advantage of the facilities offered by the framework (i.e. using annotations)?
I think for example to the query strings, or the payload of a POST request.
You can expose the same endpoint, with different action methods and HTTP actions of course.

Thanks! 😄

@igorgiovannini igorgiovannini added the question Further information is requested label Mar 15, 2021
@polishq
Copy link
Contributor

polishq commented Mar 16, 2021

Hi @igorgiovannini , thanks for the question!

If I understand correctly, you want to know why we do not take advantage of annotations like [HttpPut], [HttpGet], and [HttpDelete] to handle different actions for the same endpoint. And also why we do not use [FromBody] to get the payload automatically parsed.

We do not use annotations to define the path a controller method supports because we use our dotnet/services.json file to define the routes. This is because before reaching our app, the requests will reach the VTEX IO Router, so both of them need to understand the same route definitions (otherwise we would need to synchronize the routes definitions, which is error-prone).
The service.json route definition associates a controller method to a path. Having multiple controller methods for the same path would be possible only if we had the HTTP action to combine with the path in the route definition.

That said, we can use these annotations. The problem is that we need to use different endpoints for each action (one for a PUT, one for a GET, and another one for a DELETE, for instance). Having one controller method per action, you can also use [FromBody], [FromQuery], and cache annotations as you would do in any .Net app.

In this particular example, we want to be RESTful and have one endpoint to handle multiple HTTP actions, so we need to have only one controller method and check the actions and bodies when receiving the requests.

Long story short, we do not support RESTful APIs more easily because our route definitions do not have the HTTP actions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants