Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
332 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 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...