Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
O

octocrab

> 编程语言
Open source

A modern, extensible GitHub API Client for Rust.

1.4K stars0 likes0 views
WebsiteGitHub

About

A modern, extensible GitHub API Client for Rust.

Octocrab: A modern, extensible GitHub API client.

Octocrab is a third party GitHub API client, allowing you to easily build your own GitHub integrations or bots in Rust. Octocrab comes with two primary sets of APIs for communicating with GitHub, a high level strongly typed semantic API, and a lower level HTTP API for extending behaviour.

Adding Octocrab

Run this command in your terminal to add the latest version of Octocrab.

bash
cargo add octocrab

Semantic API

The semantic API provides strong typing around GitHub's API, a set of models that maps to GitHub's types, and auth functions that are useful for GitHub apps. Currently, the following modules are available as of version 0.54.

  • actions GitHub Actions
  • activity GitHub Activity
  • apps GitHub Apps
  • billing Billing
  • checks GitHub Checks
  • classroom GitHub Classroom
  • code_scannings Code Scanning
  • codes_of_conduct GitHub Codes of Conduct
  • codespaces GitHub Codespaces
  • commits GitHub Commits
  • copilot GitHub Copilot
  • current Information about the current user
  • dependency_graph Dependency Graph
  • enterprises GitHub Enterprises
  • events GitHub Events
  • gist_comments Gist Comments
  • gists Gists
  • git GitHub Git Database API
  • gitignore Gitignore templates
  • graphql GraphQL
  • hooks Webhooks
  • issues Issues and related items, e.g. comments, labels, etc.
  • licenses License Metadata
  • markdown Rendering Markdown with GitHub
  • marketplace GitHub Marketplace
  • meta GitHub Metadata
  • migrations Migrations
  • orgs GitHub Organisations
  • packages GitHub Packages
  • projects GitHub Projects
  • pulls Pull Requests
  • ratelimit Rate Limiting
  • repos Repositories
  • search Using GitHub's search
  • security_advisories Security Advisories
  • teams Teams
  • users Users
  • workflows GitHub Workflows

Getting a Pull Request

rust
// Get pull request #5 from `XAMPPRocky/octocrab`.
let issue = octocrab::instance().pulls("XAMPPRocky", "octocrab").get(5).await?;

All methods with multiple optional parameters are built as Builder structs, allowing you to easily specify parameters.

Listing issues

…

HTTP API

The typed API currently doesn't cover all of GitHub's API at this time, and even if it did GitHub is in active development and this library will likely always be somewhat behind GitHub at some points in time. However that shouldn't mean that in order to use those features, you have to fork or replace octocrab with your own solution.

Instead octocrab exposes a suite of HTTP methods allowing you to easily extend Octocrab's existing behaviour. Using these HTTP methods allows you to keep using the same authentication and configuration, while having control over the request and response. There is a method for each HTTP method, get, post, patch, put, delete, all of which accept a relative route and a optional body.

rust
let user: octocrab::models::User = octocrab::instance()
    .get("/user", None::<&()>)
    .await?;

Each of the HTTP methods expects a body, formats the URL with the base URL, and errors if GitHub doesn't return a successful status, but this isn't always desired when working with GitHub's API, sometimes you need to check the response status or headers. As such there are companion methods _get, _post, etc. that perform no additional pre or post-processing to the request.

rust
let octocrab = octocrab::instance();
let response = octocrab
    ._get("https://api.github.com/organizations")
    .await?;

// You can also use `Uri::builder().authority("<my custom base>").path_and_query("<my custom path>")` if you want to customize the base uri and path.
let response =  octocrab
    ._get(Uri::builder().path_and_query("/organizations").build().expect("valid uri"))
    .await?;

You can use the those HTTP methods to easily create your own extensions to Octocrab's typed API.

rust
use octocrab::{Octocrab, Page, Result, models};

trait OrganisationExt {
  async fn list_every_organisation(&self) -> Result<Page<models::Organization>>;
}

impl OrganisationExt for Octocrab {
  async fn list_every_organisation(&self) -> Result<Page<models::Organization>> {
    self.get("/organizations", None::<&()>).await
  }
}

You can also easily access new properties that aren't available in the current models using serde.

rust
#[derive(Deserialize)]
struct RepositoryWithVisibility {
    #[serde(flatten)]
    inner: octocrab::models::Repository,
    visibility: String,
}

let my_repo = octocrab::instance()
    .get::<RepositoryWithVisibility>("https://api.github.com/repos/XAMPPRocky/octocrab", None::<&()>)
    .await?;

Static API

Octocrab also provides a statically reference counted version of its API, allowing you to easily plug it into existing systems without worrying about having to integrate and pass around the client.

rust
// Initialises the static instance with your configuration and returns an
// instance of the client.
octocrab::initialise(octocrab::Octocrab::builder());
// Gets a instance of `Octocrab` from the static API. If you call this
// without first calling `octocrab::initialise` a default client will be
// initialised and returned instead.
let octocrab = octocrab::instance();

GitHub Webhook Support

octocrab provides deserializable datatypes for the payloads received by a GitHub application responding to webhooks. This allows you to write a typesafe application using Rust with pattern-matching/enum-dispatch to respond to events.

Note: Webhook support in octocrab is still beta, not all known webhook events are strongly typed.

…

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Rust

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言