Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
329 views
in Technique[技术] by (71.8m points)

restful url - Why does including an action verb in the URI in a REST implementation violate the protocol?

I'm finding it necessary to understand why including action verbs in the URI violates the REST protocol for URI syntax? When I read the following article, I sense that too many people are making too much noise about verbs, and that they should be making more noise about content types:

RestWiki: Minimum Methods

In a perfect world, client browsers would all support GET, POST, PUT and DELETE for request operations. However, only GET and POST are supported, which means we're stuck trying to identify operations that should be PUT and DELETE by using common action verbs in the URL like view, create, edit, and delete.

How does this violate the spirit of the REST architectural principles, and what is the roadblock you experience by putting something like "delete" into your URL instead of using "deletion"?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The only valid reason for the guidance around URIs is to encourage proper usage of the REST verbs. If a request performs an action that is consistent with the client's expectation as per the HTTP standards then it really does not matter what the url contains.

Naming urls based on nouns makes it natural to create behaviour that is consistent with the intended purpose of GET, PUT, POST and DELETE.

When you put verbs in the URL it can become very confusing because often the http verb will have contradictory behaviour to the one in the URL. REST rules say you must respect the HTTP verb, but usually the url is more descriptive so it can be misleading.

The fact that browsers only support a subset of HTTP verbs is not really relevant because even when you do have full access to all the HTTP verbs, you still need to be able to model other verbs, like print, close, confirm, cancel.

You are absolutely right that people need to focus way more on content types than URL structure when talking about REST implementations.

Making your URLs refer to nouns is not a REST constraint, it is about encouraging people to fall into the pit of success.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...