RESTful Web API: A Comprehensive Guide
1. What is REST and RESTful?
REST stands for REpresentational State Transfer. It is a relatively new approach to writing web APIs.
RESTful refers to web services written by applying REST architectural concepts. These services focus on system resources and how the state of a resource should be transported over the HTTP protocol to different clients written in different languages. In RESTful web services, HTTP methods like GET, POST, PUT, and DELETE can be used to perform CRUD operations.
2. Architectural Style for Creating Web APIs
The architectural style for creating web APIs includes:
- HTTP for client-server communication
- XML/JSON as formatting language
- Simple URI as the address for the services
- Stateless communication
3. Tools for Testing Web APIs
Tools for testing web APIs include:
- SOAPUI tool for SOAP WS
- Firefox “poster” plugin for RESTful services
4. HTTP Methods Supported by REST
HTTP methods supported by REST are:
- GET: Requests a resource at the request URL. It should not contain a request body as it will be discarded. May be it can be cached locally or on the server.
- POST: Submits information to the service for processing; it should typically return the modified or new resource
- PUT: At the request URL it updates the resource
- DELETE: At the request URL it removes the resource
- OPTIONS: It indicates which techniques are supported
- HEAD: About the request URL it returns meta information
5. Can You Use GET Request Instead of PUT to Create a Resource?
No, you are not supposed to use POST or GET. GET operations should only have view rights.
6. What Are Resources in a REST Architecture?
Resources are identified by logical URLs; they are the key element of a RESTful design. Unlike SOAP web services, in REST, you view the product data as a resource, and this resource should contain all the required information.
7. Difference Between AJAX and REST
| AJAX | REST |
|---|---|
| In Ajax, the requests are sent to the server by using XMLHttpRequest objects. The response is used by the JavaScript code to dynamically alter the current page | REST requires the interaction between the customer and server |
| Ajax is a set of technology; it is a technique of dynamically updating parts of UI without having to reload the page | REST is a type of software architecture and a method for users to request data or information from servers |
| Ajax eliminates the interaction between the customer and server asynchronously | REST have a URL structure and a request/response pattern the revolve around the use of resources |
8. Key Characteristics of REST
Some key characteristics of REST include:
- REST is stateless, so there is no storage of session data on the client
- With a well-applied REST API, the server could be restarted between two calls as every data is passed to the server
- Web service mostly uses POST method to make operations, whereas REST uses GET to access resources
9. Different Application Integration Styles
The different integration styles include:
- Shared database
- Batch file transfer
- Invoking remote procedure (RPC)
- Swapping asynchronous messages over a message-oriented middle-ware (MOM)
10. Difference Between PUT and POST
“PUT” puts a file or resource at a particular URI and exactly at that URI. If there is already a file or resource at that URI, PUT changes that file or resource. If there is no resource or file there, PUT makes one
POST sends data to a particular URI and expects the resource at that URI to deal with the request. The web server at this point can decide what to do with the data in the context of the specified resource
11. Markup Language for RESTful Web APIs
JSON and XML are the two markup languages that can be used in RESTful web APIs.
12. Difference Between RPC or Document Style Web Services
In document style web services, we can transport an XML message as part of a SOAP request, which is not possible in RPC style web service. Document style web service is most appropriate in some applications where the XML message behaves as a document and the content of that document can alter, and the intention of the web service does not rely on the content of the XML message.
13. JAX-WS and JAX-RS
Both JAX-WS and JAX-RS are libraries (APIs) for doing communication in various ways in Java. JAX-WS is a library that can be used to do SOAP communication in JAVA, and JAX-RS lets you do REST communication in JAVA.
14. Tools or APIs for Developing or Testing Web APIs
Testing tools for web services for REST APIs include:
- Spring REST web service using MVC
- Jersey API
- CFX
- Axis
- Restlet
15. Difference Between SOAP and REST
| SOAP | REST |
|---|---|
| SOAP is a protocol through which two computers communicate by sharing XML documents | REST is a service architecture and design for network-based software architectures |
| SOAP permits only XML | REST supports many different data formats |
| SOAP-based reads cannot be cached | REST reads can be cached |
| SOAP is like a custom desktop application, closely connected to the server | A REST client is more like a browser; it knows how to standardized methods and an application has to fit inside it |
| SOAP is slower than REST | REST is faster than SOAP |
| It runs on HTTP but envelopes the message | It uses the HTTP headers to hold meta information |
