From f3294b3e9bf72982742256fbc1b6e1cdf8e74d58 Mon Sep 17 00:00:00 2001 From: Lalit Ghongade <35134946+lalitghongade@users.noreply.github.com> Date: Tue, 12 Sep 2023 10:27:18 +0530 Subject: [PATCH] principles and constraints to design and build --- restful-web-services.md | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/restful-web-services.md b/restful-web-services.md index caa8efc..15e3400 100644 --- a/restful-web-services.md +++ b/restful-web-services.md @@ -1 +1,37 @@ ## RESTful Web Services + +# What does it take to be a RESTful service? + +To create a RESTful service, you need to follow a set of architectural principles and constraints that define the REST (Representational State Transfer) style. Here are the key characteristics and requirements to make a service RESTful: + +Statelessness: Each client request to the server must contain all the information needed to understand and process the request. The server should not rely on any previous requests or client state. This makes the service scalable and easy to maintain. + +Client-Server Architecture: Separate the concerns of the client (user interface) and the server (data storage and processing). This separation improves scalability and allows clients and servers to evolve independently. + +Uniform Interface: Maintain a consistent and uniform interface for interacting with resources. The uniform interface includes the following constraints: + +Resource-Based: Resources (e.g., data objects) are identified by unique URIs (Uniform Resource Identifiers). Each resource should have a distinct URI, and clients use standard HTTP methods (GET, POST, PUT, DELETE) to perform CRUD (Create, Read, Update, Delete) operations on these resources. + +HTTP Methods: Use standard HTTP methods to indicate the desired action on a resource. For example, GET retrieves resource data, POST creates a new resource, PUT updates an existing resource, and DELETE removes a resource. + +Representation: Resources can have multiple representations (e.g., JSON, XML, HTML). Clients can specify their preferred representation format using request headers (e.g., Accept) or negotiate content types. + +Stateless Communication: Each request from the client to the server should be self-contained, including all necessary information. The server should not store client state between requests. + +Layered System: Allow for the use of intermediaries such as load balancers, caches, and proxies to enhance scalability, security, and performance. Each layer in the system should have a specific role and responsibility. + +Resource Hierarchy: Organize resources in a hierarchical manner, enabling navigation between related resources using URIs. For example, /users might lead to a list of users, and /users/{id} might provide details about a specific user. + +HTTP Status Codes: Use standard HTTP status codes (e.g., 200 OK, 201 Created, 404 Not Found, 500 Internal Server Error) to indicate the outcome of each request accurately. + +Content Negotiation: Allow clients to specify the format they prefer for resource representations using HTTP headers like Accept. This enables flexibility for clients with different requirements. + +Hypermedia (optional): Implement HATEOAS (Hypertext As The Engine Of Application State) to provide links or navigation information within resource representations, allowing clients to discover and interact with related resources dynamically. This is an optional but powerful feature of REST. + +Security and Authentication: Implement appropriate security measures to protect resources and data. This may involve using authentication mechanisms, authorization checks, and secure communication protocols (e.g., HTTPS). + +Documentation: Provide clear and comprehensive documentation for your API, including resource URIs, supported HTTP methods, request and response formats, and any authentication requirements. Good documentation helps developers understand how to use your API effectively. + +To create a RESTful service, you'll typically use a web framework or technology stack that supports HTTP, such as Spring Boot (Java), Express.js (Node.js), Django (Python), or similar frameworks. You'll define your resources, their URIs, and implement the appropriate HTTP methods to handle client requests while adhering to the RESTful constraints mentioned above. + +