javascript - How to name operations that do not conform to CURD in REST style URLs?
PHP中文网
PHP中文网 2017-06-20 10:07:48
0
4
993

Currently, the Internet is filled with a large number of articles about how to design RESTful API (for convenience, "RESTful API" is abbreviated as "API" below). However, there is no "universal" design standard: how to authenticate? What is the API format? When you start to write an app, especially when the back-end model part has been written, you have to go to great lengths to design and implement the public API part of your app. Because once released, the API released to the outside world will be difficult to change.

Question 1:
Send email /mail/1/send using POST /mail/send using POST
How to name the URL

Question 2
Get a specific user list /getVipUser /user/vip /getUserList?type=vip
How to name the URL

Question 3
I am very confused about whether to use camel or snake shape. I have used both. Some people say it doesn’t matter, but I am still confused.

PHP中文网
PHP中文网

认证0级讲师

reply all(4)
Ty80

Restful is just a set of reference specifications. My understanding is that there is no one-size-fits-all standard in the field of software development, only different best practices. As for the API, it only needs to be easy for developers to distinguish. You don’t have to force yourself to do it for the sake of specifications. Standard, as long as the function is implemented, who cares what your API looks like.

洪涛

You can check out Ruanyifeng’s blog post:
http://www.ruanyifeng.com/blo...

Regarding whether to use camel case or snake case, it should be all lowercase

学霸

vip can be used as a resource
GET vips/user/{id} OR GET users/vip/{id} Get a single resource
GET vips/user OR GET users/vip Get multiple Resources

迷茫

You may want to refer to these resources: restful-api-design-references - RESTful API design reference list, which can help you understand REST-style interface design more thoroughly.

In the actual application of RESTful api, the design of Github API v3 can be said to be a model, you can also take a look.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template