codeminer.api provides a REST API wrapper for the
codeminer package,
enabling access to clinical code mappings through HTTP endpoints.
Install from GitHub:
# install.packages("pak")
pak::pak("codeminer-io/codeminer.api")library(codeminer.api)
# Set up database path
Sys.setenv(CODEMINER_DB_PATH = "path/to/database.duckdb")
# Start API server
run_codeminer_api()Visit http://127.0.0.1:8000/__docs__/ for interactive API
documentation.
library(codeminer.api)
# Create temporary database
db_path <- tempfile(fileext = ".duckdb")
codeminer::create_dummy_database(db_path)
Sys.setenv(CODEMINER_DB_PATH = db_path)
# Start API in background
bg <- run_codeminer_api(background = TRUE, port = 8888, quiet = TRUE)
# Query the API
library(httr2)
response <- request("http://127.0.0.1:8888/DESCRIPTION") |>
req_url_query(pattern = "asthma", code_type = "icd10") |>
req_perform()
resp_body_json(response)
# Stop server
bg$kill()If the API server you are calling requires authentication, configure a
strategy once per session (or via CODEMINER_DEV_USER for development
servers) and the regular helpers attach the appropriate headers
automatically. See vignette("authenticated-requests") for the full
walkthrough, including how to plug in custom auth schemes via
auth_custom().
See vignette("codeminer.api") for detailed documentation including:
- Background vs foreground modes
- API endpoint reference
- Process management
- Troubleshooting guide
- Production deployment tips
GET /DESCRIPTION: Search codes by description patternGET /CODES: Look up specific codes by code valueGET /__docs__/: Interactive API documentation (Swagger UI)