rest Flashcards
what is rest
REST (representational state transfer) can essentially be seen as a set of constraints, which should be ad-
hered when designing an API. The restraints should improve scalability,
remixability, usability and accessibility of the program
what 5 constraints define REST?
- Resource Identification (RI): Every resource that can be accessed
should be named. This also means that anything that can be named
is a resource. In the web URIs provide a way global addressing space
for resource and service discovery. - Uniform Interface (UI): There should be a small set of operations
(GET, POST, DELETE,…) that can be applied to all resources.
This results in a small set of verbs and a large set of nouns. Verbs
can be expanded if needed. Operations should adhere to the CRUD
(Create, Retrieve, Update, Delete) principle. - Self-describing Messages (SDM): Resources are abstract entities, they
cannot be accessed directly, we identify them (RI) and access them
(UI). The resources are accessed by accessing a representation of the
resource. Which representation is used (e.g. JSON, XML, CSV,
XHTML, SVG, RDF,…) is made clear, then this is sufficient. - Hypermedia as the Engine of Application State (HATEOAS): The re-
source representation (SDM) contains a link to the identifiable re-
source (RI). Now the resources and their representations can be ac-
cessed through link navigation. RESTful applications navigate with
traversal paths contained in the resource representation. Link se-
mantics determine the navigation to the next resource. - Stateless Interactions (SI): States on the server side of the application
should be avoided. No history of requests is kept the server should
treat every request like a new one. The resource state can be managed
by the server it is the same for all clients and can be changed by the
client. Client state managed by the client itself. Each client manages
its own state.
How are the REST style constraints related to its goals?
- Scalability: By making the system stateless, it is easy to scale the
systems user base. Also by the UI it is easy to add new resources
since they only have to interact with a few words. - Simplicity: RESTful desing adheres to well established stadards. This
simplifies the design and implementation process. - Data independence: Because of the SDM a plethora of users can ac-
cess the resources in a way that suites their needs. Each resource can
be represented in multiple ways. - Performance: The usage of lightweight message formats like JSON
(SDM) allows for better performance.
what’s richardson’s model?
it is a model that classifies Web APIs based on their adherence and conformity to each of the model’s four levels.
What are the maturity levels in Richardson’s model? Which
REST principles are they related to?
Level 0: POX (Plain old XML)
HTTP is used as a transport system for remote interactions. No
web mechanics are used, HTML is a tunneling mechanism for RPC.
Resources are identifiable and can be represented in any way. Data
and meta-data is contained in the message body
Level 1: Resources (RI)
In this level all resources are uniquely identifiable. For example doc-
tors or appointment slots. This directly corresponds to the resource
identification restraint.
Level 2: HTTP verbs (UI & SDM)
This level adds the usage of HTTP verbs. This means that resources
are called with a verb based on how the user wants to interact with
the resource. Responses always carry a status code telling the user
about success or failure of the request. Meta-data is used to identify
the resource in URI. This corresponds to the uniform interface and
self describing messages restraints.
Level 3: Hypermedia Controls (HATEOAS & SI)
This level introduces hypermedia controls. This means that it pro-
vides the representation (link) to the next valid state change opera-
tions of the resource. It also provides the URI of the resource in the
response. This allows for dynamic adjustment of links to resources.
This corresponds to the Hypermedia as the Engine of Application
State and Stateless Interactions restraints.
what are 5 best practices according to Masse’s book?
- Hierarchical relationships should be represented by a /.
http://localhost:8080/Category/Subcategory/Products
Here a category contains a subcategory which in turn contains prod-
ucts. - Plural nouns should be used when appropriate.
http://localhost:8080/Organization/Departments/1
This indicates that an organization has many departments. - Design should improve readability. This means to use lower case let-
ters, - instead of , and avoid special characters.
http://localhost:8080/House/number-of-rooms
instead of
http://localhost:8080/House/#ofRooms - File extensions should not be used (.html, .asp,…)
- Query parameters should be used for filtering.
http://localhost:8080/Organization/Departments?name=HR
Here the query paramenter is ?name=HR - URIs should not be used wiht CRUD operations.
Do not use
http://localhost:8080/Organization/get-Departments/1
but rather
http://localhost:8080/Organization/Departments/1 coupled with a GET
request