Web API vs. RESTful services - web-services

I have been asked about the difference between Web API and RESTful services and that is also an interesting question to me. From my point of view, the only possible difference between RESTful service and Web API can be considered as that RESTful services are inherently meant to be stateless (although we can use cookies), while the concept of being inherently stateless does not apply to Web APIs as we can use sessions (can't be used in RESTful service).
However, I decided to post this question to see if there are any other potential differences that distinguish these two technologies from one another.

You're comparing a programming framework and a design paradigm. That's not a fair comparison.
Web API is a web service application framework. You can implement a REST API using it, but you don't have to. You can also write RPC-style services in it, or really just any kind of application that talks HTTP but doesn't (strictly) adhere to the REST principles.

REST is just an architectural style. It's not any protocol or framework. You can implement RESTful services using many frameworks and programming languages. Web API is just one of them for .NET.
It's true that RESTful services are stateless.
Here is the list of main REST constraints:
Client-Server
Stateless
Cache
Uniform interface
Layered system
Code-On-Demand
For more details about REST architecture I recommend Roy Fielding's publications under this link.
Coming back to your doubts, you can implement RESTful service with Web API framework, but only if you follow the rules of REST architectural style.

Related

Protocol supported by rest webservice

I am trying to learn rest web service and every where i found written that rest works on HTTP protocol. I just want to know what other protocol can be used for building rest service. Link for an example will be great help
REST is 'bound' to HTTP, since the use of the HTTP methods GET, POST, PUT, DELETE is quite central to REST.
First of all, REST is is a software architecture style for building scalable web services.
You are talking about REST when applied to webservices.
Web service APIs that adhere to the REST architectural constraints are
called RESTful APIs.
To answer your question
what other protocol can be used for building rest service
I first need to clarify some things:
You are asking about underlying web service protocols.
Now a web service is "a software system designed to support interoperable machine-to-machine interaction over a network". The network you are interested in is also the best know i.e TCP/IP aka the internet.
Now you are interested in particular about web services which adhere to the REST architectural constraints.
A REST-compliant Web service would be one who's primary purpose of the service is to manipulate representations of Web resources using a uniform set of stateless operations.
The protocol that is used for a RESTful web service
First you need to understand that you are addressing the application layer of the OSI model. HTTP is an application layer protocol of the OSI model.
Theoretically protocols from this list(application layer protocols) which :
can be used to build web services
conform to the REST architectural constraints (stateless,layered system)
could be used for a REST-ful service.

Can we use SOA architecture in RESTful web services?

While implementing REST web services, is it possible to use SOA concepts?
I don't quite understand the nature of your question but it is actually the other way around because SOA is more a design pattern that evolves around breaking down modules of a system into its own independent service, where service could (or could not) be a REST web service. If that is your question, then yes, an SOA system can use REST web services.
Having a bunch of web services or rest services or COrba services does not make it SOA. SOA is a architectural design pattern that can be applied regardless of the technology used. Like Leo said it is a design pattern
SOA is a software design paradigm. Its a high level concept for designing a software . A design paradigm or pattern is a collection of best practices that are used by many programmer over the years and make them as a standard.
While REST is an architectural design pattern that is used to defined or orchestrate a web application.
Now for designing a SOA you can use any of underlying technology i.e REST or SOAP. Both are different in nature and architecture wise. Any IT organization uses SOA for exposing its business process as a business services that are well orchestrated as IT services over IT infrastructure. All these business services are loosely coupled , platform independent and interoperable. So just to wrap up all SOA is a software design paradigm that is used to orchestrate the business services and these business services are loosely coupled and interoperable. To implements SOA and your business services you can use any architectural pattern or technology like REST or SOAP.
Question should be reversed:
Can we use RESTful web services in SOA architecture
To which the answer is yes you can.
However, I assume you actually mean
Can we use RESTful web services in SOA architecture, as the primary
means of communication between services.
Some (myself included) would argue that services consuming REST on other services for anything other than POST operations violate the second tenet of SOA which states that Services are autonomous.

Do RESTful web services support both contract-first and contract-last approaches?

Does a RESTful web service (e.g. in a JAX-RS implementation) support both contract-first (top-down) approach and contract-last (bottom-up) approach?
Do RESTful web services support both contract-first and contract-last approaches?
It depends on what tools/frameworks you use.
What you are talking about applies to a SOAP web service and its accompanying WSDL.
A WSDL describes what a web service expects as input and what should a client expect as output. It defines the contract to be followed in order for both parties to communicate with each other. You can obtain the WSDL by doing contract-first or contract-last and you can later use this WSDL to generate code for a client stub or a service skeleton.
But doing REST isn't the same as doing SOAP. Processes that worked for SOAP (a protocol) can't necessarily be applied to REST (an architectural style) just because we are familiar with them.
Unlike SOAP that exposes methods and method signatures, REST exposes resources. An understanding of the media types used in the exchange of those resources is all a REST client needs in order to communicate with a REST web service. There is no need for a separate document to describe the resources.
Because of the HATEOAS principle, REST clients are more dynamic and can adapt to other services that communicate using the same media types. Exposing static service description documents would be limiting for a REST service.
Having said that, there are REST tools that do expose a description document, for example Jersey who exposes a WADL (contract-last). I'm sure you can use the published WADL to build client stubs and I don't see a reason why you couldn't write the WADL by hand (contract-first) and use it to generate stubs and skeletons. But as I said, that might not be the best solution for REST.
Here are some posts you might want to read to form an opinion if contract-last or contract-first approaches make sense in REST:
Does REST Need a Description Language?
Why the slow WADL uptake?

Web Services - What exactly are they?

What does a Web service really mean ? I am not looking for a theoretical explanation, I am looking for something practical.
I was thinking that anything I can call from an external client is a Web service, so a basic PHP which returns JSON data could be a Web service.
But then I started reading about Web services in W3Schools.org and I got confused. If the PHP URL which returns JSON data is a web service, why would I need to do SOAP, WDSL etc ... to create a Web service. Isn't it extra work?
Also, if SOAP is the way data is sent back and forth, what about other transport types?
What differentiates a RESTful Web service from a SOAP based web service?
When you are talking about a webservice people generally misunderstand what it means, a webservice is simply a way to interact between a and b that abstracts the use of local technology standards. A WSDL defines the way in which the SOAP message is being sent over the channel. REST uses JSON over HTTP, WSDL uses SOAP over HTTP.
The advantage of a webservice is, say you develop one piece of code in .net and you wish to use JAVA to consume this code. You can interact directly with the abstracted layer and are unaware of what technology was used to develop the code.
SOA is a set of design paradigms and standards that tell you how to develop your services, in SOA each service is meant to comply with the principles listed below. WSDL is generally linked with but not essential for a SOA solution. If you wish to learn about SOA google "Thomas Erl SOA".
Priciples of SOA
Standardized service contract
Service loose coupling
Service abstraction
Service reusability
Service autonomy
Service statelessness
Service discoverability
Service composability
This Q&A Restful vs Other Web Services brings a lot of light to what is a webserver, and differences from SOAP and REST. Id recommend to read all the answers (many of them are very good).

Are EJBs applications like Web Services?

Is developping an EJB application is considered like a web services ?
Or the two are different ?
Or you can make EJBs like web services ?
My answer would be yes and no.
No in the sense that EJB is a programming model. This programming model contains concepts such as security, transaction demarcation, state management and persistency (stateful or stateless beans), and more. While web service is more a remoting technology, that is, a way to connect systems, which is SOAP in the case of web service. Under this perspective both are completely different topic (Web service could be compared to RMI-IIOP though).
Yes in the sense that both are usually referred as technologies to expose a service to the outside (as long as it's stateless). Under this perspective they belong to the same category. And an EJB can indeed be exposed very easily as a web service by annotating the bean accordingly.
Hope it brings some light to the distinction.
An EJB is an object that has some useful methods, typically Business Logic, and those methods can be invoked by clients in a number of ways - one of those ways can be a Web Service interface.
In development terms it's pretty much just a matter of annotating the EJB with your chosen interfaces style.
Putting the logic in an EJB can be a good idea because you get easy control over Transactional behaviour, declarative Security and scalability from the EJB container.