R/sag_api.R

Defines functions api_url sag_api

Documented in sag_api

#' Build a SAG web service url
#'
#' utility to build a url with optional query arguments
#'
#' @param service the name of the service
#' @param ... name arguments will be added as queries
#'
#' @return a complete url as a character string
#'
#' @examples
#'
#' sag_api("hi", bye = 21)
#' sag_api("StockList", year = 2021)
#'
#' @export
#' @importFrom httr parse_url build_url GET
sag_api <- function(service, ...) {
  url <- paste0(api_url(), "/", service)
  url <- parse_url(url)
  url$query <- list(...)
  url <- build_url(url)

  url
}

api_url <- function() {
  "https://sag.ices.dk/SAG_API/api"
}

Try the icesSAG package in your browser

Any scripts or data that you put into this service are public.

icesSAG documentation built on Oct. 30, 2024, 9:14 a.m.