Search⌘ K

Creating the Register Endpoint

Explore how to create a user registration endpoint in a Deno application using Oak for routing. Learn to handle POST requests, validate JSON inputs, implement a user controller, and connect business logic with the web layer. This lesson guides you through building a functional register endpoint that processes user data securely.

Create the endpoint logic

With the business logic and data accessing logic ready, the only thing missing is the endpoint that the user can call to register itself.

For the register request, we’ll implement a POST request with endpoint /api/users/register, expecting a JSON object with a property named user containing two properties, username and password.

The first thing we’ll have to do is declare that our createServer function in src/web/index.ts will depend on the UserController interface to be injected. Let’s get started:

  1. In src/users/types.ts, create the UserController interface. Make sure it’s also exported in src/users/index.ts:
...