Hyphen, underscore, or camelCase as word delimiter in URIs?

后端 未结 6 1369
别跟我提以往
别跟我提以往 2020-12-04 04:07

I\'m designing an HTTP-based API for an intranet app. I realize it\'s a pretty small concern in the grand scheme of things, but: should I use hyphens, underscores, o

6条回答
  •  有刺的猬
    2020-12-04 05:00

    Short Answer:

    lower-cased words with a hyphen as separator

    Long Answer:

    What is the purpose of a URL?

    If pointing to an address is the answer, then a shortened URL is also doing a good job. If we don't make it easy to read and maintain, it won't help developers and maintainers alike. They represent an entity on the server, so they must be named logically.

    Google recommends using hyphens

    Consider using punctuation in your URLs. The URL http://www.example.com/green-dress.html is much more useful to us than http://www.example.com/greendress.html. We recommend that you use hyphens (-) instead of underscores (_) in your URLs.

    Coming from a programming background, camelCase is a popular choice for naming joint words.

    But RFC 3986 defines URLs as case-sensitive for different parts of the URL. Since URLs are case sensitive, keeping it low-key (lower cased) is always safe and considered a good standard. Now that takes a camel case out of the window.

    Source: https://metamug.com/article/rest-api-naming-best-practices.html#word-delimiters

提交回复
热议问题