RESTful Web Services (original) (raw)

Last Updated : 6 Sep, 2025

RESTful Web Services are a way of designing and developing web services that use REST (Representational State Transfer) principles. They enable applications to communicate over the web using standard HTTP methods, such as GET, POST, PUT and DELETE. REST is lightweight, stateless and widely used in modern web and mobile applications.

Workflow-of-Restful-Web-Services

workflow

What is REST

REST or Representational State Transfer is an architectural style that can be applied to web services to create and enhance properties like performance, scalability and modifiability.

REST became popular due to its simplicity and adaptability

RESTful Architecture

Principles of RESTful Applications

**1. URI Resource Identification

**2. Uniform Interface

**3. Self-Descriptive Messages

**4. Hyperlinks for State Interactions (HATEOAS)

**Example

Here is an example of a simple RESTful service that allows a client to create, read, update and delete (CRUD) a resource :

Java `

// GET /resource/123 Returns the state of the resource with ID 123 app.get('/resource/:id', function(req, res) { var id = req.params.id; var resource = findResourceById(id); res.json(resource); });

// POST /resource Creates a new resource with the state specified in the request body app.post('/resource', function(req, res) { var resource = req.body; var id = createResource(resource); res.json({ id: id }); });

// PUT /resource/123 Updates the state of the resource with ID 123 with the state specified in the request body app.put('/resource/:id', function(req, res) { var id = req.params.id; var resource = req.body; updateResource(id, resource); res.sendStatus(200); });

// DELETE /resource/123 Deletes the resource with ID 123 app.delete('/resource/:id', function(req, res) { var id = req.params.id; deleteResource(id); res.sendStatus(200); });

`

**In this example:

Advantages of RESTful web services

  1. **Speed: As there is no strict specification, RESTful web services are faster as compared to SOAP. It also consumes fewer resources and bandwidth.
  2. **Compatible with SOAP: RESTful web services are compatible with SOAP, which can be used as the implementation.
  3. **Language and Platform Independency: RESTful web services can be written in any programming language and can be used on any platform.
  4. **Supports Various Data Formats: It permits the use of several data formats like HTML, XML, Plain Text, JSON, etc.