REST Flashcards
Layered Architecture concept:
Lower layer provides services to upper layer
many upper layers can use the same lower layer
Knowledge of only the next layer (no jumping over layers)
lower layers can not call upper layers
What is REST (the concept)
REpresentational State Transfer
-We transfer a representation of the current state of a resource
REST Constraints
- Client-Server
- Stateless
- Cacheable
- Layered System
- Uniform interface
- Code-on-demand (optional)
Client-Server constraint
Seperation of concerns
Many user interfaces for the same data/business logic
User interface/frontend can evolve seperately from the backend
Applications can be ported to several platforms (multiple frontends for the same backend)
Stateless constraint
Visibility: For debugging, you only need to look at a single request
Reliability: Recovery from failure is easier (just resend the request)
Scalability: No need to store state on the server, easier to build distributed applications
Cacheable constraint
Responses can be reused
User-perceived performance increased
downside: Reliability
Layered System constraint
Easy to replace hidden layers
easy to add/remove layers
downside: overhead and latancy
Code-on-demand constraint
Server can send executable code to the client
Allows to extend client with additional functionality
downside: Visibility
Uniform interface constraint
A uniform interface is required between components
Identification of resources
-Every resource can be identified using a URI/URL
Manipulation through representations
-No direct interaction with the data… use JSON or XML
Self descriptive messages
-Each request can be understood by the server in isolation… it has all the information… what is it requesting? JSON or something
HATEOAS
-Use links
Why use REST
Helps build applications that are scalable, general and maintainable
Resources
Use plural nouns
Useful things to keep in mind
Version your API (http://blabla.com/v1/
Use sorting, paging, field selection for GET requests
- GET http://blabla.com/users?sortBy=username
- > returns all users sorted by usernames
Return the created updated deleted resource when the request is successful