Episode 104 - REST API - The Good, the Bad and the Ugly

The Backend Engineering Show with Hussein Nasser

Episode | Podcast

Date: Wed, 07 Aug 2019 13:27:56 GMT

<p>&nbsp;</p> <p>REST stands for Representational state transfer its is an architecture that became very popular in build web APIs. It was the dissertation of Roy Fielding. In this video we discuss what makes an API RESTFUL, the REST APIs constrains, ill the show you an example of a RESTFUL api in github.&nbsp;</p> <p><strong>Representation and State transfer</strong>&nbsp;</p> <p><strong>Representational</strong>&nbsp;</p> <p>The resource is a representation or meta data, but the actual backend could be something else and stored differently. An&nbsp;</p> <p>Example, could be a user resource could be represented as a JSON object but it is stored on the backend as relation DBMS tables such as postgres.&nbsp;</p> <p><strong>State transfer</strong></p> <p>The application server is stateless, and when we want communicate we transfer the current state of with each request. Thus the state transfer. &nbsp;</p> <p>Example, lets say you are uploading a 5MB file in 5 chunks each is 1 MB in size and assemble it on the backend. The REST api end point takes the content along with a upload sequence, then persist it on a storage backend such as S3. Each chunk request could hit a completely different stateless server and the transfer will work fine since we are transferring the state (upload sequence) with every request. The client maintains the state in this case.&nbsp;</p> <p><strong>Rest constraints</strong></p> <p><strong>Client/server architecture</strong></p> <p>Is there separation of concern? Can you upgrade your server without upgrading client? Can you upgrade the server without upgrading the client?&nbsp;</p> <p><strong>Statelessness</strong></p> <p>Is your api stateless? Can you restart your backend server and clients of your api resume working normally without failing? Can you add a non sticky load balancer and transfer the load between the servers without the client breaking?</p> <p><strong>Cachablity</strong>&nbsp;</p> <p>Can resources that can be cached be cached with your api? And is there a way to identify stale resources?&nbsp;</p> <p><strong>Layered systems</strong></p> <p>Can I insert gateways and proxies and firewalls silently without this architecture breaking? Load balancers&nbsp;</p> <p><strong>Uniform interface</strong></p> <p>Resource identification (uri)&nbsp;</p> <p>Resource Representation (json)&nbsp;</p> <p><strong>HATEOAS</strong></p> <p>Hypermedia as an engine to application state</p> <p>Initial link can link to the rest ( github)&nbsp;</p> <p>Github&nbsp;</p> <p>Emojis&nbsp;</p>