File: http.R

package info (click to toggle)
r-cran-natserv 1.0.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 672 kB
  • sloc: sh: 13; makefile: 2
file content (18 lines) | stat: -rw-r--r-- 556 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
ns_base <- function() 'https://explorer.natureserve.org'

ns_GET <- function(url, query = list(), ...){
  cli <- crul::HttpClient$new(url = url, opts = list(...))
  temp <- cli$get(query = query)
  temp$raise_for_status()
  x <- temp$parse("UTF-8")
  return(x)
}

ns_POST <- function(url, body, query = list(), ...){
  cli <- crul::HttpClient$new(url = url, opts = list(...),
    headers = list(Accept = "application/json"))
  temp <- cli$post(body = body, query = query, encode = "json")
  temp$raise_for_status()
  x <- temp$parse("UTF-8")
  return(x)
}