Skip to content

Commit

Permalink
docs: Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
fussybeaver committed Oct 20, 2024
1 parent 0efd70d commit 115c1db
Show file tree
Hide file tree
Showing 4 changed files with 170 additions and 183 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Check
on:
repository_dispatch:
types:
- github-openapi-release
- octokit/openapi-release

jobs:
update:
Expand Down
115 changes: 59 additions & 56 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,37 @@
[![license](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
[![docs](https://docs.rs/roctogen/badge.svg)](https://docs.rs/roctogen/)
[![GitHub workflow](https://github.com/github/docs/actions/workflows/default.yml/badge.svg)](https://github.com/fussybeaver/roctogen/actions/workflows/default.yml)
[![GitHub workflow](https://github.com/fussybeaver/roctogen/actions/workflows/default.yml/badge.svg)](https://github.com/fussybeaver/roctogen/actions/workflows/default.yml)

## Roctogen: a rust client library for the GitHub v3 API
## Roctogen: Rust Client Library for GitHub v3 API

This client API is generated from the [upstream OpenAPI
specification](https://github.com/github/rest-api-description/). The library currently supports
webassembly and both tokio and non-tokio based asynchronous requests and minimal dependency blocking
synchronous requests with a choice of different clients, enabled through cargo features:
**Roctogen** is a Rust library generated from the [GitHub REST API OpenAPI
specification](https://github.com/github/rest-api-description/). providing
comprehensive support for the GitHub v3 API. It offers flexible support for
both synchronous and asynchronous HTTP clients, including WebAssembly
compatibility. You can choose between multiple client libraries via Cargo
features, or integrate your own HTTP client handling by extending the
`adapter` subsytem:

- `isahc` feature (*sync* and non-tokio based *async*): [Isahc HTTP client](https://github.com/sagebind/isahc)
- `reqwest` feature (*async*) [Reqwest client](https://github.com/seanmonstar/reqwest)
- `ureq` feature (*sync*) [Ureq client](https://github.com/algesten/ureq)
- `reqwest`: Enables asynchronous requests using the [Reqwest client](https://github.com/seanmonstar/reqwest)
- `ureq`: Provides synchronous requests with the [Ureq client](https://github.com/algesten/ureq)

## Install
### Installation

Add the following to your `Cargo.toml` file
To include Roctogen in your project, add it to your `Cargo.toml`:

```nocompile
[dependencies]
roctogen = "0.12"
roctogen = "*"
```

## API
### Documentation

[API docs](https://docs.rs/roctogen/latest).
- [API docs](https://docs.rs/roctogen/latest).
- [Endpoints](https://docs.rs/roctogen/latest/roctogen/endpoints/index.html).

[Endpoints](https://docs.rs/roctogen/latest/roctogen/endpoints/index.html).
#### Supported endpoints:

Supported endpoints:
---
Roctogen supports a wide range of GitHub API endpoints, including:

- [Meta](https://docs.rs/roctogen/latest/roctogen/endpoints/meta/struct.Meta.html)
- [Issues](https://docs.rs/roctogen/latest/roctogen/endpoints/issues/struct.Issues.html)
Expand Down Expand Up @@ -69,31 +70,37 @@ Supported endpoints:
- [Codespaces](https://docs.rs/roctogen/latest/roctogen/endpoints/codespaces/struct.Codespaces.html)
- [Emojis](https://docs.rs/roctogen/latest/roctogen/endpoints/emojis/struct.Emojis.html)

## Usage
For a full list of supported endpoints, refer to the [API documentation](https://docs.rs/roctogen/latest/roctogen/endpoints/index.html).

A quick example of this library:
### Usage

Here's a basic example demonstrating how to use Roctogen:

```rust
use roctogen::api::{self, repos};
use roctogen::adapters::client;
use roctogen::auth::Auth;

let auth = Auth::None;
let client = client(&auth).expect("Cannot create new client");
let per_page = api::PerPage::new(10);

let mut params: repos::ReposListCommitsParams = per_page.as_ref().into();
params = params.author("fussybeaver").page(2);

repos::new(&auth).list_commits("fussybeaver", "bollard", Some(params));
repos::new(&client).list_commits("fussybeaver", "bollard", Some(params));
```

### Async
#### Asynchronous Requests

All the `async` methods are suffixed with `_async`, and are available on the wasm target or `isahc` and `reqwest` adapters.
For async support, use the `_async` suffix for method calls. These are
available with the `reqwest`, or WebAssembly targets.

### Webassembly
#### Webassembly

To compile for webassembly, you can use [`wasm-pack`](https://github.com/rustwasm/wasm-pack) or compile with the
`wasm32-unknown-unknown` target:
Roctogen can be compiled to WebAssembly using
[`wasm-pack`](https://github.com/rustwasm/wasm-pack) or by directly
targeting wasm32-unknown-unknown:

```nocompile
$ wasm-pack build
Expand All @@ -103,80 +110,76 @@ $ wasm-pack build
$ cargo build --target wasm32-unknown-unknown
```

If you are building a [cloudflare worker](https://workers.cloudflare.com/), you would use the
`wrangler` wrapper:

```nocompile
$ wrangler preview --watch
```

### Client adapters

Building on non-`wasm` targets generally requires adopting a feature for the desired
client adapter.

#### Isahc

Compiling for the [`isahc`](https://github.com/sagebind/isahc) client required the `isahc` feature:

```nocompile
$ cargo build --features isahc
```
Roctogen supports multiple HTTP clients, or you can write your own. Enable
the desired client using Cargo features:

#### Reqwest

Compiling for the [`reqwest`](https://github.com/seanmonstar/reqwest) client required the `reqwest` feature:
Compile with Reqwest support using the `reqwest` feature:

```nocompile
$ cargo build --features reqwest
```

#### Ureq

Compiling for the [`ureq`](https://github.com/algesten/ureq) client required the `ureq` feature:
Compile with Ureq support using the `ureq` feature:

```nocompile
$ cargo build --features ureq
```

## Generate the API
#### Custom Client Adapters

It's possible to write your own adapter, by extending
`roctogen::adapters::Client`. This allows you to handle rate limiting and
pagination - an example of extending the base adapter is available in the
example [`min-req-adapter`](/fussybeaver/roctogen/tree/master/examples/min-req-adapter).

### Generating the API

The majority of code is generated through the [Swagger OpenAPI
generator](https://github.com/swagger-api/swagger-codegen) (version 3). Building requires the
[`mvn`](https://maven.apache.org/install.html) Java build tool, pegged at Java version 8 (so
you'll need an appropriate JDK).
Roctogen's code is largely generated from the GitHub REST API specification
using the [Swagger OpenAPI
generator](https://github.com/swagger-api/swagger-codegen) (version 3).
Building the API requires the Java-based `mvn` tool with JDK 8 installed:

```nocompile
$ mvn -D org.slf4j.simpleLogger.defaultLogLevel=info clean compiler:compile generate-resources
```

## Tests
### Testing

Beware, tests that are not run with the `mock` feature are currently still doing real HTTP requests to the GitHub API.
Roctogen supports both WebAssembly and synchronous test environments. Be
aware that some tests perform real HTTP requests to the GitHub API unless
mocked.

Run the wasm tests:
- **WebAssembly Tests**:

```nocompile
$ wasm-pack test --firefox --headless
```

Run the sync tests:
- ** **Synchronous Tests**:

```nocompile
$ cargo test --features isahc,mercy,squirrel-girl,inertia,starfox --target x86_64-unknown-linux-gnu -- --nocapture
```

In order to avoid GitHub's API rate limiting, you can run the non-wasm tests using wiremock.
You'll need to start wiremock in the background:
To avoid GitHub's API rate limits during testing, you can use WireMock to
mock the API locally. Run the following to start WireMock, and run the
tests with the `--mock` feature:

```nocompile
$ docker run -d --name wiremock -p 8080:8080 -v $PWD/tests/stubs:/home/wiremock
rodolpheche/wiremock
$ cargo test --feature mock,ureq
```

#### Regenerate the wiremock stubs

You should regenerate the stubs if the remote API has changed:
If the GitHub API changes, you can regenerate the WireMock stubs:

```nocompile
$ docker run -d --name wiremock -p 8080:8080 -v $PWD/tests/stubs:/home/wiremock -u (id -u):(id -g) rodolpheche/wiremock --verbose --proxy-all="https://api.github.com" --record-mappings
Expand Down
Loading

0 comments on commit 115c1db

Please sign in to comment.