标签云

微信群

扫码加入我们

WeChat QR Code

What exactly is RESTful programming?


see also the answer at the following link stackoverflow.com/a/37683965/3762855

2019年09月24日43分06秒

REST might be getting a bit old now ;) youtu.be/WQLzZf34FJ8

2019年09月24日43分06秒

Also, refer this link for some more information news.ycombinator.com/item?id=3538585

2019年09月24日43分06秒

Corrections to accepted answer here. stackoverflow.com/questions/19843480/…Or here roy.gbiv.com/untangled/2008/rest-apis-must-be-hypertext-drivenOr here web.archive.org/web/20130116005443/http://tomayko.com/writings/…

2019年09月24日43分06秒

OLIVER.KOO nice observation. It's just that I asked it at a time when it was kind of a new thing. It was getting thrown around a lot but not many people knew what it was about. At least I didn't, and it seems that me asking this has helped them because they also wanted to know.

2019年09月24日43分06秒

Lisiting Available Idempotent Operations: GET(Safe), PUT & DELETE (Exception is mentioned in this link restapitutorial.com/lessons/idempotency.html). Additional Reference for Safe & Idempotent Methods w3.org/Protocols/rfc2616/rfc2616-sec9.html

2019年09月24日43分06秒

a) the important point about GET is safeness, not idempotence, b) Abhijeet: RFC 2616 has been obsoleted in 2014; see RF 7230ff.

2019年09月24日43分06秒

This is wrong. Read this for correct interpretation of REST roy.gbiv.com/untangled/2008/rest-apis-must-be-hypertext-drivenor this stackoverflow.com/questions/19843480/…

2019年09月24日43分06秒

kushalvm That academic definition of REST is not used in practice.

2019年09月24日43分06秒

Effectively we can wonder if a concept is operational since we fail to simple giveit a stable and understandable definition for all

2019年09月24日43分06秒

No.REST didn't just pop up as another buzzword.It came about as a means of describing an alternative to SOAP-based data exchange.The term REST helps frame the discussion about how to transfer and access data.

2019年09月24日43分06秒

Nonetheless, the heart of REST (in practical application) is "don't use GET to make changes, use POST/PUT/DELETE", which is advice I've been hearing (and following) since long before SOAP appeared.REST has always been there, it just didn't get a name beyond "the way to do it" until recently.

2019年09月24日43分06秒

Don't forget "Hypertext as the engine of application state".

2019年09月24日43分06秒

This answer misses the point. HTTP is barely mentioned in Fielding's thesis.

2019年09月24日43分06秒

This answer doesn't mention the purpose of REST, and makes it seem like it's all about clean URIs. While this might be the popular perception of REST, D.Shawley's and oluies answers are more accurate - it's about being able to take advantage of features built into the architecture, like caching, by working with it instead of against it. Prettier URIs are mostly a common side effect.

2019年09月24日43分06秒

An answer providing a reading list is very appropriate for this question.

2019年09月24日43分06秒

Thanks for the update.PUT and POST don't really map one-to-one with update and create.PUT can be used to create if the client is dictating what the URI will be.POST creates if the server is assigning the new URI.

2019年09月24日43分06秒

Don't forget PATCH.

2019年09月24日43分06秒

A URN is a URI that uses the urn: scheme.Conceptually there is no difference; however, a URN does require that you have a separately defined method to "locate" the resource identified (named) by the URN.Care must be taken to ensure that you don't introduce implicit coupling when relating named resources and their location.

2019年09月24日43分06秒

ellisbben Agreed. If I understand correctly this is the dissertation that gave rise to REST: ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm

2019年09月24日43分06秒

For me this answer captured the essence of the desired answer.Simple and pragmatic.Granted there are lots of other criteria, but the example provided is a great launch pad.

2019年09月24日43分06秒

In the last example, pbreitenbach uses PUT fname=Jonny. This would set lname and age to default values (probably NULL or the empty string, and integer 0), because a PUT overwrites the whole resource with data from the representation provided. This is not what is implied by "update", to do a real update, use the PATCH method as this does not alter fields which are not specified in the representation.

2019年09月24日43分06秒

Nicholas is right. Also, the URI for the first POST creating a user should be called users because /user/1 makes no sense and there should be a listing at /users. The response should be a 201 Created and not just OK in that case.

2019年09月24日43分06秒

This is just an example of an API not necessarily a RESTful api. A RESTful has constraints it adheres to. Client-Server Architecture, Stateless, Cache-ability, Layered System, Uniform Interface.

2019年09月24日43分06秒

Thats a very compact answer that covered all http servlet access methods

2019年09月24日43分06秒

I think this answer touches the key point of understanding REST: what does the word representational mean. Level 1 - Resources says about state. Level 2 - HTTP Verbs says about transfer (read change). Level 3 - HATEOAS says driving future transfers via representation (JSON/XML/HTML returned), which means you've got known how to say the next round of talk with the information returned. So REST reads: "(representational (state transfer))", instead of "((representational state) transfer)".

2019年09月24日43分06秒

Difference between REST and POX

2019年09月24日43分06秒

This is a really concise answer. Can you also describe why the REST is called stateless?

2019年09月24日43分06秒

That's "using HTTP properly", which is not the same as "restful" (although it's related to it)

2019年09月24日43分06秒

You could also use /user/del/2 and /user/remove/2 or... GET/DELETE/PUT/POST are just the standardised, "proper" way to do such things (and as Julian says, that's not all there is to REST)

2019年09月24日43分06秒

Sure, but that's no reason to avoid them.. REST just saves you reinventing the wheel each time. For an API, REST is great (consistency!), but for structuring a random website it doesn't really matter I'd say (it can be more hassle than it's worth)

2019年09月24日43分06秒

Vadim, that would be simply RPC. It's also dangerous to use GET for modifying data since (among other reasons) a search engine may spider your deletion links and visit them all.

2019年09月24日43分06秒

aehlke - I think the real question there would be "Why does an anonymous user have the ability to delete records from your system?"

2019年09月23日43分06秒

but not straight-forward .. makes it more complicated that it needs to be.

2019年09月24日43分06秒

Also, even though the terms REST and RESTful are used almost exclusively in the realm of web applications right now, technically there's nothing tying REST to HTTP.

2019年09月24日43分06秒

Fielding's blog has some good, easier to comprehend articles on REST and common misconceptions: roy.gbiv.com/untangled/2008/rest-apis-must-be-hypertext-driven

2019年09月23日43分06秒

HankGay I think the reason it's not more esoteric is that most web service developers see REST as a wonderful simplification over alternatives like SOAP.They don't necessarily stick to getting all the REST technicalities correct - and that probably drives the REST fanatics mad - but in most cases they probably don't need to worry about things like making sure their results are "hypermedia-enabled".

2019年09月23日43分06秒

cool links, thanks.I'm tired of these REST guys that say some example is not "REST-ful", but then refuse to say how to change the example to be REST-ful.

2019年09月23日43分06秒

What does Communication is Done by Representation mean?

2019年09月24日43分06秒

so .... how would that example be restful? how would you change the url to make it restful?

2019年09月24日43分06秒

hasen: Using one resource for all operations might be necessary for RESTfulness, but isn't sufficient.

2019年09月24日43分06秒

ok well .. could you explain further? What's the point of saying "no these guys are wrong .. I know what's right" without saying what you know (or think) to be right?

2019年09月24日43分06秒

I gave the link to Fielding's description.I thought I said exactly the relevant diff to the other responses: needs to be driven by hypertext.If "/user/123" comes from some out-of-band API documentation, then it's not RESTful.If it comes from a resource identifier in your hypertext, then it is.

2019年09月24日43分06秒

Or you can use an entry point like /users/ and it will give you a list of user resources AND the URI for each. Then resources are discoverable and navigation is hypertext-driven.

2019年09月24日43分06秒

A MVC viewpoint: The blog Rest Worst Practices suggested not to conflating models and resources. The book Two Scoops of django suggests that the Rest API is the view, and not to mix business logic into the view. The code for the app should remain in the app.

2019年09月24日43分06秒

Another good article: WikiPedia about Resource-Oriented Architecture

2019年09月24日43分06秒

Fielding added some further rules RESTful APIs/clients have to adhere

2019年09月23日43分06秒

doesn't answer the question as wel as the others, but +1 for information that is relevant!

2019年09月24日43分06秒

I think this answers the question too, but for example statelessness is missing from it. Every constraint is important... The standard media type part is not always true. I mean there are layers of understanding. For example if you use RDF, then the media type can be understood, but the meaning of the content not. So the client needs to know the vocabulary as well. Some people are experimenting with this kind of REST APIs and a general REST vocab to describe hyperlinks, etc. hydra-cg.com

2019年09月24日43分06秒

Several quotes, but not a single source mentioned. Where did you get this?

2019年09月24日43分06秒

"Saying that Rest is just a syntactic change... makes it look like it has no benefits and is purely cosmetic" --- that's exactly why I am reading answers here on SO. Note that you did not explain, why REST is not purely cosmetic.

2019年09月24日43分06秒

this is not even a proper answer

2019年09月24日43分06秒

If you look at the constraints Fielding put on REST you will clearly see that an API needs to have reached Layer 3 of the RMM in order to be viewed as RESTful, though this is simply not enough actually as there are still enough possibilities to fail the REST idea - the decoupling of clients from server APIs. Sure, Layer 3 fulfills the HATEOAS constraint but it is still easy to break the requirements and to couple clients tightly to a server (i.e. by using typed resources)

2019年09月24日43分06秒