22 Jul: A REST is Good for You
Respresentatonal State Transfer (REST) is way of providing interoperability between two network connected systems. In a minimal (and somewhat over-simplified) statement:
"A REST API defines a set of functions which developers can perform requests and receive responses via HTTP protocol such as GET and POST."
Properties of REST:
- Client-server - the client and server are seperate and independant
- Stateless - each request is complete, no session state is maintained by the server
- Uniform Interface - request use: POST (create), GET (read), PUT (edit) and DELETE. Objects are manipulated using URIs which are their sole identifiers
- Cachable - responses must indicate whether they can be cached, and clients must cache if possible for scalability
- Layered - an architecture of hierachical layers where each component only needs to understand the layed it interacts with
- Code-on-demand (optional) - servers can temporarily extend client function by transfering executable code
Example of using a REST API:
GET https://www.googleapis.com/compute/v1/projects/project/zones/zone/disks/disk
where the variables project, zone and disk define the object you want to get the properties of. Or for an API that doesn't need authentication:
$ curl -s https://api.tfl.gov.uk/Line/jubilee/Status | json_pp | grep statusSeverityDescription
"statusSeverityDescription" : "Good Service",
Here the variable is "jubilee" (the name of one of the London Underground lines), and this call is to check the status for any disruption, so it will just read information therefore its a GET request. The documentation covers the details how to interact with the API:
https://api.tfl.gov.uk/swagger/ui/index.html?url=/swagger/docs/v1#!/Line/Line_StatusById.