'Using DTO or request.param in Express/TypeORM Rest Api

Im creating a REST API with express/TypeORM in Typescript.

My application stores users in mysql database, and users can create boards in the application.

When a user create a board i have to send the userId from the client to the backend to identify which user created this table.

1: I created a DTO:

POST: v1/boards

import { Board } from "../entity/Board";

class BoardDTO {
    
    public board!: Board;

    public userId!: string;
};

export default BoardDTO;

to get the userId from the request.body.

OR

  1. I can send the userId in the request url as a parameter like this:

POST: v1/:userId/boards

The question is which one is the better pattern in real life??? get userId from body or from the request.param????



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source