Home  >  Q&A  >  body text

php - api路径怎么命名比较好?

api给app、spa或者后台某些需要ajxa的功能使用的

看到有的人使用index?c=reg&xxx=xxx
有的使用
/user/getList
/user/get_list
/user/get-list
/user.getList
还有一种是/userGetList 这种推荐吗?

然后剩下的是REST方式
/user/1 get post put path
/user

但是我发现国外那些什么网盘 twiiter github用rest多,国内基本很少,而且好像也不适合?

我想大声告诉你我想大声告诉你2687 days ago564

reply all(1)I'll reply

  • 習慣沉默

    習慣沉默2017-05-16 13:09:20

    RESTful is just a specification, not a standard that forces you to use it. Following it can make your API interface more standardized and professional. Of course, you can also choose not to use it. Just implement it according to the specifications agreed by your own project team.
    RESTful mode:
    http(s)://server.com/app-name/{version}/{domain}/{rest-convention}
    Here, {version} represents the version information of the api. {domain} is an area that you can use to define any technical (for example: security - allow specified users to access this area.) or business reasons. (For example: the same functions are under the same prefix.)
    {rest-convention} represents the agreed set of REST interfaces in this domain.

    There are a lot of RESTful guarantee specifications available online, so I’ll just post the address here for your reference.
    http://www.coderli.com/transl...

    reply
    0
  • Cancelreply