Are all web services automagically restful web ser

2019-02-19 20:11发布

问题:

Are all web services through HTTP and not SOAP automagically restful web services?

I have been hearing the term "Restful web services" everywhere.. but ain't it simply a plain old "web service that uses http".

I have a url at A.php and clients request data from me like this: A.php?parameters_supplied_here_etc_etc

And since the url has a length limit, for longer messages they will send a POST request with the parameters to A.php

Basically if anyone wants to talk to my server/database, it goes through the page at A.php

So can I say that it's a restful web service??

回答1:

One of the cornerstones of "REST" architectural style is using HTTP to its full potential (GET, HEAD, PUT, POST, DELETE, content-type, etags, cache control, etc) instead of as a tunnel. If you do just that, you already win a lot, and I think you should feel entitled to call your service "REST Inspired" or something. From there you can use all the existing building blocks of HTTP infrastructure to your advantage, instead of having to work against them.

It's often tempting to come up with your own RPC or CRUD protocol over HTTP, and reinvent the wheel. The result is usually quite contrary to REST principles.



回答2:

There are at least two types of web services around:

  • SOAP web services - using XML Schema to strictly define XML messages, typically, but not necessarily using HTTP as a transport protocol. Reliable and standardized, they've been around for quite some time, although sometimes considered heavyweight.

  • RESTful web services - less rigid, using plain HTTP protocol, taking advantage of built-in GET/POST/PUT/DELETE methods to perform CRUD operation on resources. Content negotiation (typically XML or JSON), redirects (Location header) and user-friendly URLs make RESTful web serives getting more attention.

These are two different communication protocols, you can migrate one into another, but no automatic conversion ever happens.



回答3:

No, because to be a REST service, it needs to fulfil certain criteria. See wikipedia

There is a quote there which might answer your question better than I can:

SOAP RPC contrast

SOAP RPC over HTTP, on the other hand, encourages each application designer to define a new and arbitrary vocabulary of nouns and verbs (for example getUsers(), savePurchaseOrder(...)), usually overlaid onto the HTTP POST verb. This disregards many of HTTP's existing capabilities such as authentication, caching and content type negotiation, and may leave the application designer re-inventing many of these features within the new vocabulary.[8] Examples of doing so may include the addition of methods such as getNewUsersSince(Date date), savePurchaseOrder(string customerLogon, string password, ...).



回答4:

The acronym REST stands for Representational State Transfer, this basically means that each unique URL is a representation of some object. Other (such as SOAP) are more RPC-like. SOAP refers to Simple Object Access Protocol and is usually overlaid onto the HTTP POST. SOAP has recently been stretched in some REST-like directions.



回答5:

Are all web services automagically restful web services?

No there is no magic. You have SOAP and other protocols which are not RESTful.



回答6:

If all your request go through the same URI then this is a clear sign that you're not using URIs to identify the individual resources of your system, so - no.

That being said; there are more constraints such as uniform interfaces, or hypermedia-driven.