You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Remote Procedure Calls are the "old way" of implementing client-server communication
RPC style applications implement their own protocols on top of HTTP (e.g. by using SOAP)
HTTP requests sent by an RPC style application will usually look something like this:
POST /searchUser HTTP/1.1
Host: www.myapp.com
...
<SearchUserRequest name="Ernie" />
POST /deleteUser HTTP/1.1
Host: www.myapp.com
...
<DeleteUserRequest name="Ernie" />
All the data needed to process a client request is inside the HTTP request body
URI path is only an arbitrary identifier to select the correct endpoint
All the data required to understand a server response is inside the HTTP response body
HTTP/1.1 200 OK
Content-Length: 81
...
<DeleteUserResponse>
<Error>User could not be found</Error>
</DeleteUserResponse>
So what do RESTful applications do then?
Use HTTP features to design client-server communication
But actually... RESTfulness does not require HTTP--it's just typically used, because it aligns well with the requirement to provide a standardized application interface
Identify data and functionality using URIs
RESTful applications use Unique Resource Identifiers to identify the target of a request
/users represents a collection of users in the system
/users/ernie represents a specific user
Resources are hierarchical
/users/ernie/messages represents the messages of a user
Everything is a resource--even operations
/users/ernie/block represents an operation on a user
Use query parameters to filter a resource
/users/ernie/messages?contains=bert
Support HTTP methods on resources
Clients can act upon resources using the HTTP methods/verbs GET, PUT, POST, and DELETE
GET /usersretrieves the list of users in the system
DELETE /users/erniedeletes a user from the system
POST /userscreates a new user which is specified by the request body
PUT /users/ernie2updates a user
PATCH should be used when partially updating a resource
But actually... RESTfulness does not require HTTP methods--they are just typically used, because they suit the requirement to have a set of simple, well-defined operations
Respond with helpful HTTP status codes
The status code of a server response should actually convey meaning
Of course the body of the response can still contain additional information