REST API and its Component
Basically, there are two types of web services:
- Soap web services – Simple object access
- Restful web services – REST based web services
Rest is not a tool, technology, framework or specification. It is an architectural style describe by Roy Fielding. REST stands for Representational State Transfer, which provides web services based on URLs and HTTP. It is protocol independent and follows the stateless model. REST proves to be very helpful in exposing a public API over the internet to manage create, read, update, and delete operations on the data. REST focuses on using a single consistent interface to access named resources.
Six Constraints of REST
- Stateless – Server contains no client stage. However, the client side holds the session state. Each request contains enough contexts to process the message.
- Uniform Interface – Interface between client and server, HTTP verbs (GET, PUT, POST, DELETE), URLs (resource name), and HTTP response (status, body).
- Cacheable – Server responses (representations) are cacheable, implicit, explicit, and negotiable.
- Layered System – It improves scalability. Usually, the client never informs if it is directly connected to the end server. Intermediary servers may enable load-balancing and provide shared caches to improve system scalability.
- Client – Server – Clients from Servers are separated by UI. This separation of concerns means clients are least concerned about the activities at server end, like data storage, etc.
- Code on Demand (optional) – Temporarily, servers can transfer the logic to be executed by client. In this way the functionality of a client can be customized.
Difference between REST and SOAP
- REST is an architectural style & SOAP is a protocol.
- REST stands for Representational State Transfer & SOAP stands for Simple Object Access Protocol
- REST can use SOAP web services because it is protocol independent and can use any protocol like HTTP, and SOAP & SOAP can’t use REST because it is a protocol.
- The bandwidth and resource required by REST are less as compared to SOAP.
- In REST we can use different data format such as Plain text, HTML, XML, JSON, etc. & In SOAP only XML format can be used.
- REST allows data of different formats, like Plain text, HTML, XML, JSON, etc. & SOAP defines its own security.
You may also like: How to Test Representational State Transfer (REST) Style Based Web Services?