Skip to content

Commit 76681de

Browse files
authored
Add inline usage example to README (#80)
Shows the Promise-based pattern using the OO convenience API (GitHub.get_repo) so users can understand the library's shape without navigating to the examples directory. Closes #73
1 parent 44f9755 commit 76681de

1 file changed

Lines changed: 27 additions & 2 deletions

File tree

README.md

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
Library for interacting with the GitHub REST API.
44

5-
See [the examples](examples) for usage.
6-
75
## Status
86

97
GitHub REST API is an alpha-level package.
@@ -19,6 +17,33 @@ Additional API surface and functionality will be added as needed. If you need fu
1917
* `use "github_rest_api"` to include this package
2018
* `corral run -- ponyc` to compile your application
2119

20+
## Usage
21+
22+
```pony
23+
use "github_rest_api"
24+
use "github_rest_api/request"
25+
use "net"
26+
27+
actor Main
28+
new create(env: Env) =>
29+
let auth = TCPConnectAuth(env.root)
30+
let creds = Credentials(auth, "your-github-token")
31+
32+
GitHub(creds).get_repo("ponylang", "ponyc")
33+
.next[None](PrintRepository~apply(env.out))
34+
35+
primitive PrintRepository
36+
fun apply(out: OutStream, result: RepositoryOrError) =>
37+
match result
38+
| let repo: Repository =>
39+
out.print(repo.full_name)
40+
| let err: RequestError =>
41+
out.print(err.message)
42+
end
43+
```
44+
45+
See the [examples](examples/) directory for more.
46+
2247
## API Documentation
2348

2449
[https://ponylang.github.io/github_rest_api](https://ponylang.github.io/github_rest_api)

0 commit comments

Comments
 (0)