Skip to content
This repository has been archived by the owner on Jun 20, 2022. It is now read-only.

Commit

Permalink
Merge pull request #31 from octokit/philosophy
Browse files Browse the repository at this point in the history
Documenting `go-octokit`'s philosophy
  • Loading branch information
owenthereal committed Nov 8, 2013
2 parents f33e124 + f9aa75e commit 3745e38
Showing 1 changed file with 53 additions and 11 deletions.
64 changes: 53 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,22 @@

Go toolkit for the GitHub API.

## Hypermedia-driven client
## Status

### Show a user
Very experimental. APIs are subject to change.

## Motivation

`go-octokit` is designed to be a hypermedia API client that [wraps](http://wynnnetherland.com/journal/what-makes-a-good-api-wrapper) the [GitHub API](http://developer.github.com/).

## Hypermedia agent

`go-octokit` is hypermedia-driven by default.
Under the hood, it uses [`go-sawyer`](https://github.com/lostisland/go-sawyer), the Go version of [Ruby Sawyer](https://github.com/lostisland/sawyer).

### Hypermedia in go-octokit

Resources in `go-octokit` contain not only data but hypermedia links:

```go
package main
Expand All @@ -23,7 +36,41 @@ func main() {
// Handle error
}

// Do something with user
fmt.Println(user.ReposURL) // https://api.github.com/users/jingweno/repos
}
```

### URI templates

Many hypermedia links have variable placeholders. `go-octokit` supports [URI Templates](http://tools.ietf.org/html/rfc6570) for parameterized URI expansion:

```go
package main

import "github.com/octokit/go-octokit/octokit"

func main() {
url, _ := octokit.UserURL.Expand(octokit.M{"user": "jingweno"})
fmt.Println(url) // https://api.github.com/users/jingweno
}
```

### The Full Hypermedia Experience™

If you want to use `go-octokit` as a pure hypermedia API client, you can
start at the API root and follow hypermedia links which drive the application state transitions:

```go
package main

import "github.com/octokit/go-octokit/octokit"

func main() {
rootService, _ := client.Root(nil)
root, _ := rootService.Get()

usersService, _ := client.Users(root.UserURL, octokit.M{"users": "jingweno"})
user, _ := usersService.Get()
}
```

Expand Down Expand Up @@ -59,15 +106,10 @@ func main() {

```

### Exploring hypermedia APIs

```go
rootService, _ := client.Root(nil)
root, _ := rootService.Get()
### Caching

usersService, _ := client.Users(root.UserURL, octokit.M{"users": "jingweno"})
user, _ := usersService.Get()
```
Client-side caching is the #1 thing to do to make a hypermedia client more performant.
We plan to support this in the near future.

More [examples](https://github.com/octokit/go-octokit/blob/master/examples/example.go) are available.

Expand Down

0 comments on commit 3745e38

Please sign in to comment.