I was looking at a code example in this website and I noticed that in one endpoint it used Ok() return type and in the other one it just returned the object. When should I use ActionResult's methods such as Ok(), Created(), ... and when should we just return the object?

You can use Ok(result) in the second case if you like. There is an implicit cast from T to ActionResult<T> that does the same as Ok(value), and this is the code that casts Employee in result to ActionResult<Employee>.
There is no such implicit cast to ActionResult which is used in the first case. It's not really possible to create an cast that makes sense.
If the first method returned Task<IEnumerable<Employee>>> then you could rely on the implicit cast and avoid using Ok().
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With