RESTful API Flashcards
HTTP methods
CRUD - POST (create), GET (read), PUT (update), DELETE (delete)
6 Requirements for RESTful API
1) Client-server are independent. Interact with each other through requests
2) Stateless. server doesn’t store any state about prev requests (so client request must contain all information required for server to process it)
3) Cacheable. Server includes a version number in its messages to decide if it should request a resource again or use the already cached data
4) Uniform interface: identification of resources (via a unique URI - Uniform resource identifier), Manipulation of Resources through representations (JSON, not SQL query), self-descriptive messages (application/json that tells receiver how to parse the message), HATEOAS (response from the API should include links to other parts of the API – can figure out how API works without external documentation)
5) Layered System. REST allows for API on one server, LB inbetween, data on another server
6)
RESTful stands for
representational state transfer
What IS RESTful API?
a way of writing web API (appelation programming interface) that focuses on system and state of resources and how they should be transferred over HTTP protocols.
PUT vs POST
PUT puts a file at a URI and replaces the existing one, if there is one. POST sends data to a URI and expects the resource at that URI to deal with the request.
REST uses GET
PUT responses aren’t cacheable.
Advantages / Disadvantages
Advantages: high performance, reliability, scalability. Statelessness allows client & server to operate individually. Supports various data transfer techs (JSON, XML, etc). Uses less bandwidth than other methods.
Disadvantages: HTTP methods limit you to synchronous requests. Doesn’t enforce security practices
AJAX vs REST
AJAX client can make a RESTful request to a REST API but AJAX isn’t an architectural style. It’s a web development technique for client-side applications. AJAX allows web apps to send and retrieve data from a server asynchronously without interfering with the display and behavior of the existing page.
HTTP response codes
2XX - successful request
4XX - bad or unauthorized request
5XX - service unavailable (server issue)