query_api: query_api Makes a query to the Canadian Nutrient Files API.

Description Usage Arguments Value References Examples

View source: R/utility.r

Description

query_api Makes a query to the Canadian Nutrient Files API.

Usage

1
query_api(path, apiKey = NULL, id = NULL, lang = "en")

Arguments

path

the path to the desired endpoint. (Should be one of food, nutrientamount nutrientgroup, nutrientname, nutrientsource, refuseamount, servingsize, or yieldamount.)

apiKey

key to access the API. Can be retrieved from https://hc-sc.api.canada.ca/en/detail?api=cnf#!/Nutrient/get_nutrientamount. If none is provided, @seealso get_key() will check the system environments for one.

id

the id of what you're looking for. Meaning of the id changes depending on endpoint.

lang

the language you are using and want results returned in.

Value

a structure with the parsed text response, the raw response, the endpoint path, and the id.

References

Note that this function is based on, and repeats much of the code in the R API package best practices, available at https://httr.r-lib.org/articles/api-packages.html#overall-design-1.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
## Not run: 
query_api("food")
query_api("food", id = 2314)
query_api("nutrientgroup", id = 1)
query_api("nutrientname", id = 1)
query_api("nutrientsource", id = 82)
query_api("refuseamount", id = 2314)
query_api("servingsize", id = 2314)
query_api("yieldamount", id = 2314)

## End(Not run)

jufil19/nutrientr documentation built on Feb. 22, 2022, 9:40 p.m.