路径元素的命名约定

Naming convention for path elements

我实际上正在寻找一个好的路径约定,主要是在元素之间存储 / 的位置:

我正在研究 URL convention 试图找到一个好的做法,但它没有谈论路径。

例子

让我们看一个真实的例子

const base_url = process.env.API_URL // http://localhost:3000(/)
const endpoint_path = "(/)users/auth(/)" 
const endpoint_name = "(/)tfa-validation"

// Slash before of after
let path = base_url + endpoint_path + endpoint_name; 
// Or without slash
path = `${base_url}/${endpoint_path}/${endpoint_name}`; 
path = [base_url, endpoint_path, endpoint_name].join('/')

约定是否已经存在?解决方案有什么优势吗?

我认为没有任何约定。 所以,我的意见是:

  1. 不要在端点路径或名称中使用“/”。保持它们干净,因为您可能希望隔离使用这些变量;
  2. 使用连接函数,因为它更干净。

const base_url = process.env.API_URL // http://localhost:3000
const endpoint_path = "users/auth" 
const endpoint_name = "tfa-validation"

path = [base_url, endpoint_path, endpoint_name].join('/')