[](https://hex.pm/packages/gbr_gh)
[](https://hexdocs.pm/gbr_gh/)
# 🔮 Github Rest API client by Gleam BR
It is a library to access the GitHub REST API v3. This library enables you to manage GitHub resources such as repositories, user profiles, and organizations.
> Only target javascript for now!
## Test it
```sh
gleam run -m bin/gbr_gh
```
## Support
- Browsers: See fetch API support (widely-available in all major browsers)
- TypeScript: >= 4.7 (>= 5.0 recommended)
- Node: >= 18.0.0
## How
Gleam client github api to url "https://api.github.com" generated by openapi spec from url "https://raw.githubusercontent.com/github/rest-api-description/refs/tags/v2.1.0/descriptions/api.github.com/api.github.com.json".
1. Use [openapi-typescript](https://github.com/openapi-ts/openapi-typescript) library to convert gh oas into AST and TS code.
3. Use [openapi-fetch] to fetch api resources, already included into TS code generated by gleam-br.
2. Use FFI functions in gleam to integrate this TS code.
3. `WIP` Decode main github api types into gleam code **follow bug**
## :bug: Gleam compiler bug
https://github.com/gleam-lang/gleam/issues/4287
Persist on Windows 11 in look file `./src/gbr/gh/decoder.gleam`, if try `gleam build` throw error:
> thread 'main' has overflowed its stack
```sh
gleam add gbr_gh@1
```
```gleam
import gleam/io
import gleam/javascript/promise
import gleam/list
import gleam/option.{None, Some}
import gleam/string
import gbr/gh
import gbr/shared/error
pub fn main() -> Nil {
use root <- promise.map(gh.root())
let assert Ok(root) = root
io.println(">>> ROOT OK")
io.println(root.current_user_url)
use repos <- promise.map(gh.repos(
"gleam-br",
Some(gh.GHQuery(
kind: Some("sources"),
sort: None,
direction: None,
per_page: None,
page: None,
)),
))
let assert Ok(repos) = repos
io.print(">>> USER OK")
let _ = {
use repo <- list.map(repos)
io.println(repo.name)
io.println(repo.git_url)
}
Nil
}
```
Further documentation can be found at <https://hexdocs.pm/gbr_gh>.
## Development
```sh
gleam run # Run the project
gleam test # Run the tests
```