Restful Flashcards
What is Rest?
Representational State Transfer is a software architectural style that defines a set of constraints to be used for creating Web Services.
Web Services that conform to the Rest Architectural style, called Restful Web Services, provide interoperability between computer systems on the net.
What makes a service Restful?
In the Rest architectural style, data and functionality are considered resources and are accessed using Uniform resource Identifiers (URIs), The resources are acted upon by using a set of simple, well-defined operations.
What protocols and data format do Rest services use?
JSON is a format, commonly associated with REST services, even though REST itself is format agnostic. That means that, while JSON is the most commonly used format, Rest allows you to user XML, HTML, pure text, any format.
What are the architectural constraints of Rest?
The 6 constraints are: Stateless Client/Server Cacheable Layered Architecture Uniform Interface Code on Demand
What is Stateless?
Each request from client to server must contain all of the information necessary to understand the request, and cannot take advantage of any stored context on the server. Session state is therefore kept entirely on the client.
What is Cacheable?
Cache constraints require that the data within a response to a request be implicitly or explicitly labeled as cacheable or non-cacheable. If a response is cacheable, then a client cache is given the right to reuse that response data for later, equivalent requests.
What is Uniform Interface?
By applying the software engineering principle of generality? to the component interface, the overall system architecture is simplified and the visibility of interactions is improved. In order to obtain a uniform interface, multiple architectural constraints are needed to guide the behavior of components.
identification of resources
manipulation of resources through representations
self-descriptive messages
hypermedia as the engine of application state.
What is a Layered System?
The layered system style allows an architecture to be composed of hierarchical layers by constraining component behavior such that each component cannot “see” beyond the immediate layer with which they are interacting.
What is client-server
By separating the user interface concerns from the data storage concerns, we improve the portability of the user interface across multiple platforms and improve scalability by simplifying the server.components
What is Code on Demand?
Rest allows client functionality to be extended by downloading and executing code in the form of Applets or Scripts. This simplifies clients by reducing the number of features required to be pre-implemented.
What is Caching?
the ability to store copies of frequently accessed data in several places along the request-response path.
By using HTTP headers, a origin server indicates whether a response can be cached and, if so, by whom, and for how long. Caches along the response path can take a copy of a response, but only if the caching metadata allows them to do so.
What are the pros and cons of Caching?
Optimizing the network using caching imporves the overall quality-of-service in the following ways: Reduce bandwidth Reduce latency reduce load on servers Hide network failures
What should be Cacheable?
Get requests by default unless otherwise specified
Post requests are NOT by default, but can be if an Expires or Cache-Control header with a directive, to explicitly allow caching, is added to the response.
Put and Delete requests are NOT cacheable at all.
What is Expires? (Caching)
The Expires HTTP header specifies an absolute expiry time for a cached representation.
Beyond that time, a cached representation is considered stale and must be re-validated with the origin server.
What is Cache-Control?
The header value comprises one or more comma-separated directives. The directives determine whether a response is cacheable, and if so, by whom, and for how long.
What is Compression
Compression, like encryption, is something that happens to the resource representation in transit and must be undone before the client can use the representation.
What is Accept-Encoding? (Compression)
(Request)The Accept-Encoding header says what kind of compression algorithms the client understands. two standards values are compress and gzip.
GET /employees HTTP/1.1
Host: www.domain.com
Accept: text/html
Accept-Encoding: gzip,compress
If the server cannot send a response which is acceptable according the AE header, then the server SHOULD send an error response with the 406(Not Acceptable).
What is Content-Encoding? (Compression)
(Response) If the server understands on of the compression algorithms form Accepting-Encoding, it can use that algorithm to compress the representation before serving it. When successfully compressed, server lets the client know the client know of the encoding scheme with the Content-Encoding header.
200 OK
Content-Type: text/html
Content-Encoding: gzip
If the content-coding of an entity in a request message is not acceptable to the origin server, the server SHOULD respond with a status code of 415 (Unsupported Media Type)
Note: if multiple content encodings have been applied to an entity, all the encodings MUST be listed in the order in which they were used.
What is Content Negotiation?
The process of selecting the best representation for a given response when there are multiple representations.available.
What is Server-Driven Negotiation?
Server-Driven negotiation is the selection of the best representation for a response made by an algorithm located at the server.
Practically, you will NOT find mush usage of server-side negotiations because of the assumptions made about client expectations.
What is Agent-Driven Content Negotiation? (client)
Agent driven content negotiation rely on usage of HTTP request headers or resource URI patterns.
What is COntent negotiation using HTTP headers?
At server side, an incoming request may have an entity attached to it. To determine it’s type, server uses the HTTP request
header Content-Type.
Content-Type: applicaiton/json
to determine what type of representation is desired at client side, HTTP header ACCEPT is used.
Accept: application/xml
if no Accept header is present in the request, the server can send pre-configured default representation type text/html is the default.
Another way to pass content type information to the server, the client may use the specific extension in resource URIs.
http://rest.api.com/v1/employees/20423.json
What is HATEOAS Driven Rest?
Hypermedia as the Engine of Application State is a constraint of the REST application architecture that keeps the RESTful style architecture unique from most other network application architectures.
It lets us use the hypermedia links in the response contents. It allows the client to dynamically navigate to the appropriate resources by traversing the hypermedia links.
HTTP GET http://api.domain.com/management/departments/10
{ "departmentId": 10, "departmentName": "Administration", "locationId": 1700, "managerId": 200, "links": [ { "href": "10/employees", "rel": "employees", "type" : "GET" } ] }
or
HTTP/1.1 200 OK
…
Link: <10/employees>; rel=”employees”
What is Idempotent? (Rest)
A Restful Web Service is idempotent when making multiple identical requests has the same effect as making a single request.