Today was a good day. I picked up beer and various party supplies for my friend’s birthday tonight and uploaded the mixtape I’m working on to Bandcamp. Still, I’m a tiny bit hungover and it’s not helping with learning, but I press onwards anyways. I spent today trying to learn the basic concepts and terms, to give me something to build on.
The REST in REST API is short for REpresentational State Transfer.
It’s resourced based, meaning we’re talking about things (like nouns) instead of actions (like verbs). Resources are like nouns, while methods and actions are more like verbs.
Resources can be identified by URI’s (Uniform Resource Indicators). Multiple URI’s can refer to the same resource (like a person record), and we can perform multiple operations that correspond to the http verbs (like GET, POST, etc). So there may be different ways to get different pieces of the resource data. I’m not actually sure what a URI is or does yet though.
A representation is separate from the resource itself. It is not the resource, but a representation of it. So the resource could be a person, and different representations can return different parts of it.
Now, representations are how resources get manipulated, and represent part of the resource state. They get transferred between the client and the server (the client is the thing requesting the info, which is hosted on the server. At least that’s what I think those terms mean). They’re typically given to you in JSON or XML, but most commonly XML.
Here’s a quick example:
- We have a Resource – Let’s say it’s a person record for John Smith
- We then might have a service that talks about that person’s Contact info, that uses the http verb GET. This is how you request the contact info from the record.
- Representation – is what you get back. It’s a representation of the resource state that is transferred between client and server. It could be his name, address, phone number, etc, and will appear in json or xml format.
Now to be completely honest, the video I’m learning from is not doing a great job of giving clear cut examples of what these terms are and how to use them. I feel like I have a slight grasp on it, but it’s definitely a bit tough to understand than the css lessons I’d been doing.