Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

document API package #38

Merged
merged 1 commit into from
Oct 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions browse/api.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ title: "Programmatic access (APIs)"
---

R-universe offers several APIs.
There is no authentication.

You can call the API as you prefer:

- creating your API calls "manually" in the command-line or R;
- using the [universe R package](https://docs.ropensci.org/universe/) available from rOpensci R-universe.

On this page we'll show examples using {httr2} or {universe} directly.

## Universe-specific APIs

Expand All @@ -22,6 +30,13 @@ packages <- httr2::request("https://jeroen.r-universe.dev/api/ls") |>
httr2::resp_body_json()
str(packages)
```

Or:

```{r}
packages <- universe::universe_ls("jeroen")
str(packages)
```

### Information of all packages in an universe

Expand All @@ -41,6 +56,14 @@ packages <- httr2::request("https://jeroen.r-universe.dev/api/packages") |>
# The result is a list of packages
str(packages[[1]], max.level = 1)
```

Or:

```{r}
packages <- universe::universe_all_packages("jeroen")
# The result is a list of packages
str(packages[[1]], max.level = 1)
```

### Information on a single package in an universe

Expand All @@ -57,6 +80,14 @@ v8 <- httr2::request("https://jeroen.r-universe.dev/api/packages/V8") |>
str(v8, max.level = 1)
```

Or:

```{r}
V8 <- universe::universe_one_package("jeroen", "V8")
# The result is a list of packages
str(V8, max.level = 1)
```

### Search in an universe

URL: `https://<username>.r-universe.dev/api/search`
Expand All @@ -82,6 +113,15 @@ str(deps, max.level = 1)
deps$total
```

Or:

```{r}
deps <- universe::universe_search("ropensci", query = 'needs:httr2')
# The result is a list of packages
str(deps, max.level = 1)
deps$total
```


## Search all universes

Expand All @@ -105,5 +145,13 @@ str(packages, max.level = 1)
str(packages$results[[1]])
```

Or:

```{r}
packages <- universe::global_search(query = '"weather data"', limit = 100L)
str(packages, max.level = 1)
str(packages$results[[1]])
```

Note that searching globally only returns "indexed" packages: if a package is included in several universes, it still shows up only once in search results because of our [deduplication efforts](#deduplication).

Loading