Fsa CS6 Rest
Fsa CS6 Rest
Development
• Resource
✓ Can be anything(docs, data, media, images) the web service can provide information about
✓ Each resource has a unique identifier - can be a name or a number
When a RESTful API is called, the server will transfer to the client a representation of the state of
the requested resource!
REST - example
• When a developer calls Instagram API to fetch a specific user (the
resource)
✓ the API will return the state of that user, including
▪ their name
▪ the number of posts that user posted on Instagram so far
▪ how many followers they have
▪ and more
Image Ref: Book T2: Restful Web services Leonard Richardson and Sam Ruby
SOAP Request
A sample SOAP RPC call Part of the WSDL description for Google’s search service
POST search/beta2 HTTP/1.1 <operation name="doGoogleSearch">
Host: api.google.com <input message="typens:doGoogleSearch"/>
Content-Type: application/soap+xml <output message="typens:doGoogleSearchResponse"/>
SOAPAction: urn:GoogleSearchAction </operation>
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<gs:doGoogleSearch xmlns:gs="urn:GoogleSearch">
<q>REST</q>
...
</gs:doGoogleSearch>
</soap:Body>
</soap:Envelope>
XML-RPC Example
h ow th e cl i en t tel l s th e se rve rwh ic hp art o f the d ata s et to o pe rate o n? In REST, SOAP, RPC
Method and Scoping information
• In RESTful web service,
✓ the method information goes into the HTTP method.
✓ The scoping information goes into the URI.
• Given the first line of an HTTP request to a RESTful web service you
should understand basically what the client wants to do.
• “GET /reports/docs HTTP/1.1”
• If the HTTP method doesn’t match the method information, the service isn’t
RESTful.
• The service is not resource-oriented if the scoping information isn’t in the
URI.
Key principles
• Everything is a resource
• Each resource is identifiable by a unique identifier (URI)
• Use the standard HTTP methods
• Resources can have multiple representations
• Communicate statelessly
REST Constraints
• For a web service to be RESTful, it has to adhere to 6 constraints:
✓ Client - Server separation
✓ Stateless
✓ Cacheable
✓ Uniform interface
✓ Layered system
✓ Code-on-demand (Optional)
Client - Server separation
• The client and the server act independently, each on its own
✓ Interaction between them is only in the form of
▪ requests initiated by the client only
▪ responses, which the server send to the client only as a reaction to a request
• The server sits there waiting for requests from the client to come
✓ doesn’t start sending away information about the state of some resources on
its own
✓ Responds only when a request comes in
Stateless
• Stateless means the server does not remember anything about the user who uses
the service
✓ doesn’t remember if the user already sent a GET request for the same resource in the
past
✓ doesn’t remember which resources the user of the API requested before
✓ and so on...
• Each individual request contains all the information the server needs to perform
the request and return a response, regardless of other requests made by the
same user.
• The client is responsible for sending any state information to the server whenever
it's needed.
• No session stickiness or session affinity on the server for the calling request
• Data the server sends contain information about whether or not the data is
cacheable
• The client is agnostic as to how many layers, if any, there are between the
client and the actual server responding to the request.
Code-on-demand (Optional)