Forget Controllers and Minimal APIs in .NET!

preview_player
Показать описание


Hello, everybody. I'm Nick, and in this video, I will show you how I build very fast APIs in .NET using a library called FastEndpoints!

Don't forget to comment, like and subscribe :)

Social Media:

#csharp #dotnet
Рекомендации по теме
Комментарии
Автор

We have every API built using this library. The product handles 200-300 k users and I loved working with it. I can for sure say this is a solid solution.

damiandziedzic
Автор

I prefer Controllers with calls to an underlaying service. Keeps all the related routing and URLs for a specific resource or function in one place.

henryvaneyk
Автор

I'm all for alternatives, but I much prefer minimal APIs in this case. Much less ceremony to achieve basically the same thing.

EricKing
Автор

I can see pros and cons, I think Fast Endpoints takes single responsibility principles too far. Minimal APIs sits somewhere in the middle, but I think for now, I would still prefer using Controllers in most settings, even if they perform worse. I think all of these options are about finding a balance between performance, productivity and what fits your team best. It's good that all of these options are available to us, but I would caution against pushing for one or the other as a one size fits all solution :)

Potato-ml
Автор

This seems like it has all of the verbosity of Controllers and all of the hackish looking parts of Minimal. Unless this had like a 50% performance boost over them, it's not something I'd use personally.

alexclark
Автор

This was good timing. We just started migrating our main API project at work to FastEndpoints as part of our move to vertical slice architecture.

sean
Автор

I don't understand the trend now of so much separation. A seperayion that make things even more difficult to track and find. It makes much more sense to me to use a controller that handles all the crud operations. I think next year we will be creating a class to write the endpoint name in, another class to specify the method, another class for the function.then we will end up with hundreds of files instead of 1 class 50 lines controller . And just create a mini project with hundred of classes. I find this to be extreme over complicating simple thing to satisfy the trendy urge of being over organized

facephonesy
Автор

It feels like mediatR with mapped routes

nurettinselcuk
Автор

I posted before but forgot to thanks Nick for publishing interesting content here. Thank you, Nick!

alexlo
Автор

Been using them a while and they rock. Had a few minor issues but most have been fixed. 10/10

JSullivan
Автор

I just use a static class with the handler inside per endpoint. Works very well with vertical slicing. Also makes it easy to add specific private extensions such as mapping that are only applicable for that handler.

Rick
Автор

It's great and so is the documentation. If I had used Minimal APIs, I would have ended up building an abstraction layer around it which would have ended up looking remarkably similar to FastEndpoint.

kdietz
Автор

At 8:48, you should have returned a BadRequest instead of a NotFound. The request being made to the API is invalid, the client asked for a single movie, but didn't specify which one. That is a request that shouldn't have been made, and should not be made again in the future. Hence, a BadRequest. NotFound is for when the client provides a valid id of a movie, but it doesn't exist in the datastore. Such a request is valid, and is allowed to be made again at a later time.

Returning the correct status code is important for good communication. If I receive a BadRequest when calling an API, then I know that I did something wrong, and should fix my problem. When I receive a NotFound, I might not think twice about it, and assume the item is removed for example.

I know this video isn't about status codes, but I wanted to make the remark either way, perhaps it can help someone :)

Nice video as always Nick!

CreativeBST
Автор

10:37 I love how you use a movie to create that movie!

SimoLPers
Автор

minimal api + mediator. = this. Don't have anything bad to say here, someone had an idea and built it. Respect to that. However if you wanted to sell it as "fast" just spin up a listener yourself.

Rule(s):
Thou cannot undo complexity, you can simply move or hide it.
Design around the axis of volatility.

A metric used to understand if a piece of software is good or bad?
- Does it generally and universally solve for maintainability? if yes then you're progressing and pushing forward, if no you've just built another branch of uncertainty and variance, try again.

Luckily I don't make up the rules.

TubeAccount-bf
Автор

I'm using FastEndpoints in combination with my own code generation scaffolding. Thus, one thing that makes me disagree with a lot of other comments here (i.e., fewer big files vs. lots of small files) is that when I'm using code generation, it tends to work out much better than fewer big files because if I change one endpoint, I only have to regenerate that one thing vs. the whole controller class. Then I can check in only the specific thing that changed, I have better visibility in my Git history, testing is better, rollbacks are better, etc. I like one file per endpoint.

kdietz
Автор

I also highly use it in my projects. Good thing about it is the opinionated structure. There is no deal to make in the team on how to do stuff, because it is layed out upfront and everyone needs to stick with it.

tareksalha
Автор

Nah.... still be using dem nice minimal APIs. They seem less hackish to me.

joga_bonito_aro
Автор

Been using it since you showed it... very simple and effective!

cristovaomorgado
Автор

All these junior devs in the comments who never got a chance to use Nancy, smh.

catalystcorp
join shbcf.ru