(question) How to inherit exposed controller http methods?
See original GitHub issueHi,
It’s possible to inherit parent controller methods? I tried to create kind of RestController
with CRUD methods, but the child seems to not get any of them.
Any idea?
Issue Analytics
- State:
- Created 6 years ago
- Comments:20 (7 by maintainers)
Top Results From Across the Web
c# - Inherit http verb attributes from abstract REST controller
The controller route attribute on the base class is inherited though (as stated in the docs).
Read more >17. Web MVC framework - Spring
The Spring Web model-view-controller (MVC) framework is designed around a DispatcherServlet that dispatches requests to handlers, with configurable handler ...
Read more >40+ Web API Interview Questions and Answers (2023)
There are many HTTP methods like GET, POST, PUT, etc., which can return ... You can download a PDF version of Web Api...
Read more >ASP.NET MVC Controller Overview (C#) - Microsoft Learn
Because a controller inherits from this base class, a controller inherits several useful methods for free (We discuss these methods in a moment) ......
Read more >Developer Guide: Scopes - AngularJS: API
Scope is the glue between application controller and the view. ... Controllers use scopes to expose controller methods to templates (see ng-controller).
Read more >Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This feature is available since
v4.6.0
🎉I have this exact use case and was surprised to find it didn’t work. A more concrete example (Using TypeORM):
Every single one of my TypeORM entities should expose basically the same restful CRUD interface and, using generics, be type safe about the underlying Entity model. I’ve already done this with the service that wraps the typeorm repository (EntityService<T>). An extending controller looks like:
This seems like a perfectly valid pattern to me, and one which will save me tons of boilerplate/copy and pasting. None of the essential CRUD logic differs between any of my entities. And, if it did, the most appropriate place to handle it would be the Service or Middleware/Interceptors/Pipes/Guards, not the controller. The value of REST is that the interface is based on the shape of the state being transferred and a set of known verbs. The verbs don’t change between controllers and the shape of the state is determined by the generic type argument.
If there is a limitation or difficulty in supporting this pattern I understand not being willing to support it. But to say there isn’t a valid use case is unfair.