Self-descriptive hypermedia in Riak
So… tell me about yourself.
GET /riak/people/old-macdonald Accept: application/json
Not much to say, really. My name is Old MacDonald. I have a farm.
HTTP/1.1 200 Okay
Content-Type: application/json
Link: </riak/people>; rel="up", \
</riak/schema/person>; riaktag="describedby", \
</riak/animals/trixie>; riaktag="pet", \
</riak/locations/macdonalds-farm>; riaktag="farm"
{
"name": "Old MacDonald"
}
Ya, I’ve heard the song. But lets pretend like I’m an alien.
WHAT IS A PERSON? BEEP BOOP
GET /riak/schema/person Accept: application/json
A person is an animal of the species Homo Sapien.
HTTP/1.1 200 Okay
Content-Type: application/schema+json
Link: </riak/schema>; rel="up"
{
"id": "/riak/schema/person",
"extends": "/riak/schema/animal",
"type": "Person",
"description": "A Homo Sapien",
"properties": {
"species": "homo sapien",
"arms": { "type": "number", "default": 2 },
"legs": { "type": "number", "default": 2 }
}
}
What is an animal?
GET /riak/schema/animal Accept: application/json
An animal is a member of the animal kingdom.
HTTP/1.1 200 Okay
Content-Type: application/schema+json
Link: </riak/schema>; rel="up"
{
"id": "/riak/schema/animal",
"type": "Animal",
"description": "A member of the animal kingdom.",
"properties": {
"species": { "type": "string" },
"name": { "type": "string" }
}
}
Okay, I get it. So tell me more about that `farm` you mentioned.
GET /riak/locations/macdonalds-farm Accept: application/json
Dude. My farm is insane. You would not believe how many animals I have.
HTTP/1.1 200 Okay
Content-Type: application/json
Link: </riak/people>; rel="up", \
</riak/schema/location>; riaktag="describedby", \
</riak/animals/wilbur>; riaktag="animal", \
</riak/animals/bessy>; riaktag="animal", \
</riak/animals/mr-ed>; riaktag="animal", \
</riak/animals/donald>; riaktag="animal", \
</riak/mortgages/macdonalds-farm>; riaktag="mortgage", \
</riak/mortgages/macdonalds-farm-2>; riaktag="mortgage"
{
"name": "Old MacDonalds Farm",
"geo": { "lat": "30.000635", "lng": "-95.225313" }
}
What is a location?
GET /riak/schema/location Accept: application/json
LOL wut? A location is a location. Are you high right now?
HTTP/1.1 200 Okay
Content-Type: application/schema+json
Link: </riak/schema>; rel="up"
{
"id": "/riak/schema/location",
"type": "Location",
"description": "A location",
"properties": {
"name": { "type": "string" },
"geo": {
"type": "object",
"properties": {
"lat": { "type": "number" },
"lng": { "type": "number" }
}
}
},
"links": [
{"map": "http://maps.google.com/maps?ll={geo.lat},{geo.lng}&z=18"}
]
}
No dude, I’m an alien. Remember? BEEP BOOP BEEP
Tell me about this animal on your farm.
GET /riak/animals/bessy Accept: application/json
Bessy is a dairy cow. She goes `moo`.
HTTP/1.1 200 Okay
Content-Type: application/json
Link: </riak/people>; rel="up", \
</riak/schema/cow>; riaktag="describedby"
{
"name": "Bessy the bovine",
"type": "dairy"
}
What is a `cow`?
GET /riak/schema/cow Accept: application/json
A cow is a producer of butter or a precursor to steak or an object of worship.
HTTP/1.1 200 Okay
Content-Type: application/schema+json
Link: </riak/schema>; rel="up"
{
"id": "/riak/schema/cow",
"extends": "/riak/schema/animal",
"type": "Cow",
"description": "A Cow is a bovine animal.",
"properties": {
"type": { "type": "string", "enum": [
"steer",
"dairy",
"sacred"
]},
"legs": { "type": "number", "default": 4 }
}
}
Tell me about your pet.
I still don’t know that she’s a dog. Or an animal for that matter.
I am programmed to treat URLs as opaque.
GET /riak/animals/trixie Accept: application/json
Trixie’s a 3-legged Australian Shepherd. She got hit by a car when she was
young and lost the use of her front left leg.
Wait, how did you know she is a dog if you didn’t know she is a dog?
HTTP/1.1 200 Okay
Content-Type: application/json
Link: </riak/people>; rel="up", \
</riak/schema/dog>; riaktag="describedby"
{
"name": "Trixie",
"breed": "Australian Shepherd",
"legs": 3
}
What are you talking about? I don’t even know what a dog is.
I’m an alien, remember? BEEP BOOP BOP BEEP
GET /riak/schema/dog Accept: application/json
Whatever, dude. This whole routine is gettin’ kinda played out.
HTTP/1.1 200 Okay
Content-Type: application/schema+json
Link: </riak/schema>; rel="up"
{
"id": "/riak/schema/dog",
"extends": "/riak/schema/animal",
"type": "Dog",
"description": "A Dog is a Canis lupus familiaris.",
"properties": {
"species": "Canis lupus familiaris",
"breed": { "type": "string" },
"legs": { "type": "number", "default": 4 }
}
}
Ya, you’re right. Lemme just try 1 more thing.
DELETE /riak/animals/bessy
Dude.
HTTP/1.1 204 No Content
Comments(0)