From the course: Building and Securing RESTful APIs in ASP.NET Core

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Create a registration route

Create a registration route - ASP.NET Core Tutorial

From the course: Building and Securing RESTful APIs in ASP.NET Core

Start my 1-month free trial

Create a registration route

- [Instructor] Let's make it possible for a user to register for the API by simply posting a form to the user's endpoint. I've added a form model called Registerform to the model's folder. You can find it in the exercise files This registration form takes an email, a password, and the user's first and last names. We'll let ASP.NET Core validate these parameters for us, and then create a new user in the system with these values. We need to add a method to the user service to save that user to the database. I'll start in the interface Iuserservice. I'll say Task Create/UserAsync which takes a register form. We can take advantage of a cool feature in C# 7, and return a named tuple here. So this will be a task of parens, bool succeeded, string error message. If you aren't using C# 7 in your project, you could just a simple class to hold these values instead. Now over in the default user service, I'll implement that method as a stub, and make this async. Bring this down here. There we go…

Contents