-
Notifications
You must be signed in to change notification settings - Fork 10.2k
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
Provide an API experience that scales down well and is easier to learn #27724
Comments
Hopefully this simplification approach will make DI (dependency injection) at least optional and reduce "filter magic". |
Interesting design goal for .NET 6! I think this is a great idea. I've had times when I couldn't sell people on ASP.NET because they wanted a banana, but not the gorilla and the forest too.
Call me crazy, but I like the fact that I don't have to use model binding if I don't want to. I love the simplicity of just "here's a request, it has a But, I get that it's not ideal to force people to choose between barebones approaches like that and full blown MVC. It should be a spectrum. I agree with that design goal! But please don't lose that far end of the spectrum where we get to do a lot of stuff by ourselves without .NET getting in the way.
This is a great example of something I wish was optional. For singleton dependencies, I write code like: // entrypoint.js
const myDep = ...;
app.get('my-route', () => { myDep.somethingIWantToDo(); }); Express.js lets me do that when I want to, and I love it. I usually want a DI container when I have more complex dependency needs like scoped dependencies.
Another good example that I agree with. Without filters affecting the request/response flow, I don't need to constantly search through the ASP.NET docs to see what it's doing to my request. With the NancyFx project winding down (https://github.com/NancyFx/Nancy), this is a great opportunity to give people a barebones C# API experience if they want it. |
I think ASP.NET Core should aspire to be a great platform for producing strongly-typed APIs, which can be consumed from TypeScript in automated way. I've picked TypeScript specifically because TypeScript + React/Vue/Angular + ASP.NET Core could be a killer combo, if only we could lower the friction of getting the data from/to the server. Let's just write an API method in C# and the strongly-typed TypeScript wrapper would be generated and ready to be consumed with no/minimal tweaking. The "advanced" C#/.NET features would be handled out-of-box, such as generics, async enumerables, streams, exceptions, various BCL data structures etc. The XML documentation comments would be translated to the JSDoc equivalent. We have used NSwag for this in the past with... acceptable results. We needed to heavily customize the NSwag's Liquid templates to integrate the resulting TypeScript code with our Web app's log-in, progress indication and error handing, and still had to manually write TypeScript wrappers in some cases (notably for streaming file content). We had to dig through the NSwag's source on GitHub source to figure-out what can we actually use in these templates. We had to dig more to understand how to properly integrate NSwag into our build process. We had to battle silent data loss and weird behavior. Etc, etc... It would be great if we could achieve the same just using built-in APS.NET Core mechanisms which would be better documented, better tested, better supported and just "better" generally. Sorry if this sounds ranty, it's just that APIs are at the heart of so many things these days, and APS.NET's API story seems missing in action. Yes, CORBA's and COM's heydays are long gone, but their IDL, and the seamless generation of client code from IDL is still something we can learn from, IMO. Or am I speaking out of ignorance? |
Hopefully new features will make it easier to add API endpoints as single files/classes rather than having to group them into controllers. My ApiEndpoints package has proven fairly popular and basically just enforces having a single endpoint on controllers. It works quite well. |
We're in the process of learning about Protobuf at my work and it seems to help with this use case. You can have a language agnostic schema definition and then get code generated for you in C# and TypeScript. But you do have to use it with gRPC services (not HTTP services) if you want all code generated for you, and the C# Protobuf compiler has established the pattern of a "code first" C# only approach, where you annotate C# classes and get protobuf schemas generated for you. So I could see precedent set here for a new tool that takes C# controllers, as you described, and generates TypeScript code that can act as a client for you, including the schema of the model. |
The ApiEndpoints mentioned above is described as "Razor Pages for web APIs". That's precisely what's needed to simplify a WebAPI project - one "endpoint" class per endpoint, rather than a fat controller with dozens of unrelated actions. Make it simple like it is in other platforms, e.g. Node's Express. Ideally implement that library into the framework itself. It's designed well and heavily used (check nuget stats - the devs have spoken). |
Closing this issue. Remaining Open API items will be addressed in NET7. See the following tracking issue: #37098 |
Title: Provide an API experience that scales down well and is easier to learn
ASP.NET Core does not provide a smooth way to scale an API down. We provide MVC which has lots of features, but also lots of concepts to learn. We want to provide experiences for building APIs that can start simpler, with a clearer getting started experience, and can smoothly progress to controllers if desired.
Our results from Feather studies and some of our Cloud Native user studies have shown that developers new to .NET react well to more simplified API experiences, and we think that also dovetails well with the Cloud Native theme as frequently the complexity that Controllers are designed to allow you to manage are instead managed across process/project boundaries.
This epic will allow us to enhance our API offering by extracting features currently only available in MVC, allowing them to be used outside of MVC. The intent is to allow these extracted features to be used in a functions/lambda model as well as a controller model of APIs. We started this work with Endpoint routing, but today that experience lacks a lot of desirable features, like model binding and validation, and doesn't have a clear story for better code organization once you grow beyond what fits well in an inline lambda.
Initial Principles/Goals:
Sub-issues
The text was updated successfully, but these errors were encountered: