diff --git a/browse/api.qmd b/browse/api.qmd index 3f7d439..51a1f87 100644 --- a/browse/api.qmd +++ b/browse/api.qmd @@ -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 @@ -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 @@ -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 @@ -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://.r-universe.dev/api/search` @@ -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 @@ -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).