REST Basics Flashcards
Why did technologies like SOAP and WSDL come in picture on top of HTTP?
Web APIs use HTTP, by definition. In the early days of web APIs, people spent a lot of time and effort
figuring out how to implement the features of previous-generation distributed technologies like CORBA
and DCOM on top of HTTP. This led to technologies like SOAP and WSDL.
Why did plain HTTP replace SOAP and WSDL?
Experience showed that these
technologies were more complex, heavyweight, and brittle than was useful for most web APIs. The idea
that replaced SOAP and WSDL was that you could use HTTP more directly with much less technology
layered on top.
How are modern APIs built as compared to SOAP and WSDL? Have we adopted something from past?
Most modern web APIs are much simpler than SOAP or WSDL APIs, but preserve some of
the basic ideas of remote procedure call—which is not native to HTTP—implemented much more lightly
on top of HTTP. These APIs have come to be known as RESTful APIs.
Why it pays off to follow HTTP standards in APIs?
- There is value in adhering to standards
- HTTP specifications are well known and well defined
- HTTP standards are universally accepted
- Reinventing an alternative that will serve users better are low
- Not all users will have in depth knowledge of HTTP specification but it is better investment to make them learn standard HTTP mechanism
According to HTTP standard if API uses POST to create resource which header should be included in response?
Location Header should be included in response that includes the URL of the newly created resource, along with 201 status code.
According to HTTP standard if you need to check if two people don’t try to update the same resource simultaneously which header should be used?
ETag and If-Match headers should be used, which are part of HTTP standard.
According to HTTP which header should be used if your API allows multiple formats
Use HTTP Accept-Header to provide client an opportunity to choose the format that the client wants to work with.
What is Web API?
A web API is the pattern of HTTP requests and responses that is used to acess a website that is specialized for access by arbitrary computer programs, rather than (or as well as) web browsers used by humans.
What is REST?
- Architectural style of HTTP itself
- HTTP is the reality & REST is a set of design ideas that shaped it.
- The importance of REST is that it helps us understand how to think about HTTP and its use
- The majority of modern APIs uses some subset of the concepts from HTTP, blended with some concepts from other computing technologies. For example, many web APIs are defined in terms of endpoints that have
parameters. Endpoint and parameter are not terms or concepts that are native to HTTP or REST—they are
concepts carried over from Remote Procedure Call (RPC) and related technologies.
What is RESTful API?
The term RESTful has emerged for web APIs that use more of the native concepts and techniques of HTTP than antecedent technologies did, but also blend in other concepts. Many good APIs have been designed this way, and in fact, this blended style is probably the most common API style in use. HTTP and REST are precisely defined, but the term RESTful is not.
Antoine de Saint-Exupery quote on perfection
“perfection is achieved not
when there is nothing more to add, but when there is nothing more to take away.”
What can be said about coupling of clients and servers when designing Web APIs?
One of the most important characteristics that designers of distributed APIs strive for is minimizing
coupling between the client and the server. The measure of coupling is how easily either side can be
changed without breaking the other. Minimizing coupling is one of the most difficult things to achieve
in API design.
HTTP and REST: A Data-oriented Design Paradigm. Explain this
A REST API focuses on the underlying entities of the problem domain it exposes, rather than a set of
functions that manipulate those entities.
For example if we are tracking dogs and their owners. We might expose two endpoints
1) The collection of known dogs
https://dogtracker.com/dogs
2) Individual dogs
https: //dogtracker.com/dogs/id
Similarly for owners
REST based API vs Functional based API
Consider domain of dogs and owners
Functional based API
In a functional oriented API you have endpoints which are functions like
/getAllDogs, /getAllLeashedLogs
/verifyLocation, /verifyVeterinarianLocation, /feedNeeded, /feedNeededFood, /newDog, /newDogForOwner etc.
There is no uniformity and convention in this web API which makes it difficult to predict and learn. With every new API you have to learn again as there is nothing common from previous APIs.
REST based API
A significant part of the value of basing your API design on HTTP and REST comes from the uniformity
that it brings to your API.
In REST, this idea is called the uniform interface constraint.