How to prove that a Restful Web service is a web service?

I had an interview yesterday, and I was faced with an interesting question, where did I get stuck. The question "How can you say that Restful web service is a web service?". I tried to explain all the possible ways to prove. But all the answers were blocked by the question: β€œServlets can do the same. So, servlets are a quiet web service?”

Can anyone share their thoughts?

+4
source share
6 answers

To answer your question, ask first what is a web service?

  • In purely abstract terms

A web service is a way of communication between two electronic devices on the World Wide Web. (Wikipedia)

  • Now the accepted industry standard for two devices for communication over the Internet uses XML messages (which makes it interoperable )

  • This leads us to various types of web services, mostly divided into SOAP and RESTful.

  • SOAP web services use XML (which corresponds to a specific protocol or xml scheme, which, in other words, is called WSDL ). Thus, SOAP web services establish specific rules / rules regarding the exchange of messages between web services and their clients. Messages can be exchanged using any convenient protocol except HTTP.
  • Now, in a RESTful script, you still exchange messages (xml / json, etc.), but there are no new additional specifications (I know WADL , but came up with more to provide support for RESTful tools and has nothing to do with RESTful web services)
  • RESTful does not have a new protocol definition (for messaging). It uses the already established HTTP protocol standards, which pass parameters to the URL as path elements and HTTP methods for sending data (namely GET / POST / PUT / DELETE).

Now for your question about whether servlets are insecure web services, let's see what Servlets do.

  • Accept GET / POST request
  • Returns HTML (well, generally) (which is essentially XML)

Now, if the servlet is written in such a way that it can be called with the following URL

http: //www.myrestwebservices/services/getstockquote/GOOG

This servlet

  • mapped to URL / services/getstockquote
  • gets GOOG as input in a URL path that it can parse, request some kind of system to get the latest Google stock quote.
  • Returns text / xml data to clients

    Doesn't this servlet satisfy the following basic requirements of a RESTful script?

  • Use HTTP methods explicitly
  • Be stateless.
  • Open structure directories like URIs.
  • XML Transmission, JavaScript Object Designation (JSON), (text essentially)

So technically speaking, yes, a servlet is RESTful web services, but this may not be enough for a typical business requirement for web services as such. Therefore, for full-blown RESTful web services, we need a servlet (nonetheless) written specifically to meet these basic business requirements.

+1
source

Well, you can create RESTful web services using Servlet.

A servlet helps create an HTTP response for an HTTP request. RESTful webservices is hosted on top of the HTTP protocol, so you can make a REST service using Servlet.

0
source

Any code (in any language, etc.) based on HTTP can be a calm web service if it meets the requirements of REST ...

See: http://en.wikipedia.org/wiki/Representational_state_transfer

0
source
  • All is a resource.
  • All resources set the standard interface GET, POST, PUT, DELETE
  • REST services are idempotent
  • Resources may refer to other resources.
  • Multiple views
  • Stagnant message

See post for more details above.

0
source

Your approach to such issues should be from the bottom up. Start by defining a service. Then define a web service, and then you can easily distinguish what a web service is and what is not. Typically, for such a discussion, I attack it as follows:

  • Any reusable piece of code that defines a contract for a client is a service. The desktop printer driver is a service.
  • Any service that can be used on the network (more than HTTP in a text request / resposne) is a web service.
  • The RESTful service adds more restrictions in terms of the separation of VERB vs NOUN and the concept of Resources .
  • How servlets differ from REST is the lack of a contract in Servlets, and therefore Servlets are not Services by themselves.
  • No one can stop a person who wants to implement RESTful Service using Servlets, but he is too low for the development of REST in a world where there are frameworks that facilitate development.

ALL Web Restful services in the Java world are written on top of a servlet, which is the bottom version for HTTP processing. If the transport is not HTTP , this is a service, but not a web service :)

0
source

The answer, which I think is pretty obvious, so the question they asked you is a bit strange. Both SOAP and REST-full services use HTTP as a transport mechanism, so they are in fact web services.

Their difference is that SOAP-based services are more strictly defined by a specification in which REST-full services are more similar to the architectural style, which is less limited in their implementation.

0
source

Source: https://habr.com/ru/post/1502146/


All Articles