score:1

here is a very nice tutorial from the microsoft docs, using entity framework (very nice), and some dependency injection (very very nice).

basically you create an api controller class with your crud methods in them like so:

namespace myapicontrollerclass
{
    [authorize]
    [routeprefix("users")]
    public class usersapicontroller : controllerbase
    {
        private readonly usercontext _context;

        public usersapicontroller(usercontext context)
        {
            _context = context;
        }

        [route("/login")]
        public ihttpactionresult loginuser(user user)
        {
            try
            {
                // login logic here

                return ok(); // you can return whatever you need 
            }
            catch (exception exception)
            {
                // log any issues using your preferred method of logging

                return internalservererror(); // you can return different status codes as well. depends on what you want
            }

        }
    }
}

you can read more about the authorize annotation here and customize it to your liking.

then you fire up your web project which will be available at a local url that you can set in the project's configuration say http://localhost:4000/ which then makes your controller url available at http://localhost:34501/users/login. then you use this url in your javascript call and add the user object in the request body.


Related Query

More Query from same tag