Multiple .NET User types login in one API route

Viewed 73

I have 2 types of user:

public abstract class User
{
    public Guid Id { get; set; }
    public string PhoneNumber { get; set; }
    public string Password { get; set; }
}
public class Customer : User
{
    public string Nickname { get; set; }
}
public class Vendor : User
{
    public List<int> PriceList { get; set; }
}

I would like to have an api path like : /api/user/login :

[HttpPost("login")]
public ActionResult</* MyUser */> Login(...)
{
    ...
}

Is there a way to create only one method returning my different types ?

If no, what would be the best architecture ?

  • Two routes: /api/customer/login and /api/vendor/login
  • Two routes: /api/user/customer/login and /api/user/vendor/login
  • One route: /api/user/login with an enum in the request telling which user to use

Thank you for your help !

1 Answers

You should create only one method which returns User, that will work because both Vendor and Customer are subclasses of User

[HttpPost("login")]
public ActionResult<User> Login(...)
{
    ...
}
Related