Working with a REST API: the GitHub case study
Glamorous Toolkit allows you to work with REST APIs out of the box.
Here, we take a look at how we can play with the GitHub REST API. Take a look at the related Exploring the GitHub REST API in 7' video.
As a case study we start from JSON content located at https://api.github.com/orgs/feenkcom which looks like:
The first thing we do is to get that JSON programmatically:
url := 'https://api.github.com/orgs/feenkcom'.
json := ZnClient new get: url.
Now, that's just a string. We never really want to work with a string. We'd rather parse it:
dictionary := STONJSON fromString: json.
Parsing the JSON string produces a dictionary. That's already better, but still not quite what we want. We want a custom experience for that outcome. To this end, we reify the data into a first class object:
GhOrganization new rawData: dictionary.
Once we have a dedicated object the inspector gets the opportunity of defining custom views. For example, the repositories list is described in GhOrganization>>#gtReposFor:
.
Now, try exploring. For example, what happens when you double click on a repository?