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 which looks like:

The first thing we do is to get that JSON programmatically:

url := ''.
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 := STON 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: gtReposFor: aView <gtView> ^ aView columnedList title: 'Repositories'; priority: 40; items: [ self repos ]; column: 'Repo' text: #name; column: 'Description' text: #description; column: 'Open issues' text: #numberOfOpenIssues .

Now, try exploring. For example, what happens when you double click on a repository?