GhEx.REST (gh_ex v0.1.0)

Copy Markdown View Source

Generic REST access. Any GitHub REST path is reachable through get/3, post/3, patch/3, put/3, and delete/3.

Every call returns {:ok, body, meta} on a 2xx or {:error, reason} otherwise, where reason is a GhEx.Error for an API error response or a Req exception for a transport failure. meta is a GhEx.REST.Meta struct carrying the status, response headers, parsed pagination links, and rate-limit snapshot.

Options

Per-call options are passed through to Req, so the useful ones are:

  • :params - query string parameters, e.g. params: [state: "open", per_page: 100]
  • :json - a body to JSON-encode for post/patch/put

Examples

GhEx.REST.get(client, "/repos/elixir-lang/elixir")
GhEx.REST.get(client, "/repos/o/r/issues", params: [state: "open"])
GhEx.REST.post(client, "/repos/o/r/issues", json: %{title: "Bug", body: "..."})

Summary

Functions

Auto-paginates a list endpoint into a lazy Stream of individual items.

Types

meta()

@type meta() :: GhEx.REST.Meta.t()

result()

@type result() :: {:ok, term(), meta()} | {:error, GhEx.Error.t() | Exception.t()}

Functions

delete(client, path, opts \\ [])

@spec delete(GhEx.Client.t(), String.t(), keyword()) :: result()

Issues a DELETE.

get(client, path, opts \\ [])

@spec get(GhEx.Client.t(), String.t(), keyword()) :: result()

Issues a GET.

patch(client, path, opts \\ [])

@spec patch(GhEx.Client.t(), String.t(), keyword()) :: result()

Issues a PATCH.

post(client, path, opts \\ [])

@spec post(GhEx.Client.t(), String.t(), keyword()) :: result()

Issues a POST.

put(client, path, opts \\ [])

@spec put(GhEx.Client.t(), String.t(), keyword()) :: result()

Issues a PUT.

stream(client, path, opts \\ [])

@spec stream(GhEx.Client.t(), String.t(), keyword()) :: Enumerable.t()

Auto-paginates a list endpoint into a lazy Stream of individual items.

Follows the Link: rel="next" header until GitHub stops handing one back. The first page's :params are applied once; subsequent pages use the exact next URL GitHub returns, so cursors are never double-applied. A failed page raises GhEx.Error.

client
|> GhEx.REST.stream("/repos/elixir-lang/elixir/issues", params: [state: "all", per_page: 100])
|> Stream.map(& &1["number"])
|> Enum.take(250)