The terms "REST" and "RESTful" are often used interchangeably, but they have subtle differences in their meanings.
REST (Representational State Transfer):
Constraints:
- Stateless: Each request from a client to a server must contain all the information needed to understand and fulfill that request. The server should not store any information about the client's state between requests.
- Client-Server: The architecture is divided into a client and a server, each with specific responsibilities. The client is responsible for the user interface and user experience, while the server handles the application's business logic and storage.
- Uniform Interface: The communication between the client and server should be standardized and uniform. This includes using resource-based identification, manipulation through representations, and a self-descriptive message format.
- URIs for the Twitter API:
- Retrieving Tweets: Get User Timeline: https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=username
- This URI retrieves the timeline of tweets for a specified user, identified by their screen_name. Search Tweets: https://api.twitter.com/1.1/search/tweets.json?q=searchTerm
- This URI retrieves tweets that match a specific search term, specified by searchTerm.Get Single Tweet: https://api.twitter.com/1.1/statuses/show.json?id=tweet_id
- This URI retrieves a specific tweet, identified by its tweet_id.
- Posting Tweets: Create Tweet: https://api.twitter.com/1.1/statuses/update.json?status=tweet_text
- This URI creates a new tweet with the specified tweet_text.
- Following Users: Follow User: https://api.twitter.com/1.1/friendships/create.json?screen_name=username
- Cacheability: Responses from the server can be explicitly marked as cacheable or non-cacheable to improve performance.
- Layered System: The architecture can be composed of multiple layers, with each layer providing specific functionality while remaining unaware of the existence of other layers.
- Business Logic Layer: Encapsulates application rules, business logic, and validation processes.
- Real-world example: A service layer that handles user authentication, order processing, or product management.
- Data Access Layer: Handles data persistence, communication with databases, and data retrieval.
- Real-world example: A repository layer that interacts with a database to store, update, and retrieve user data or product information.
- Infrastructure Layer: Provides underlying infrastructure services like routing, load balancing, and error handling.
- Real-world example: An API gateway that handles routing requests to different microservices, implementing load balancing and error handling mechanisms.
RESTful:
Definition: "RESTful" is an adjective derived from "REST" and is used to describe an implementation that follows the principles of REST.
Usage:
- When people refer to a "RESTful API" or "RESTful service," they mean that the API or service adheres to the principles and constraints of REST.
Characteristics:
- Resources and URIs: RESTful APIs use resources (entities) identified by URIs. The URIs represent the state of the resource and can be used to perform CRUD operations (Create, Read, Update, Delete) on that resource.
- Stateless Operations: Each request from the client to the server is independent and contains all the information necessary for the server to fulfill the request.
- Standard HTTP Methods: RESTful APIs use standard HTTP methods (GET, POST, PUT, DELETE) for different operations on resources.
- Representations: Resources can be represented in various formats (e.g., JSON, XML), and clients interact with these representations.
"REST" is an architectural style, while "RESTful" describes implementations that adhere to the principles of REST.
When people talk about a "RESTful API," they are referring to an API that follows the design principles of REST.
No comments:
Post a Comment