Learn R Programming

vindecodr (version 0.1.1)

build_nhtsa_url: Build a NHTSA URL

Description

A family of functions to build URLs for the National Highway Transportation Safety Administration (NHTSA) vehicle identification number (VIN) decoder API.

The build_nhtsa_url() function returns a closure containing the appropriate endpoint and file format request to pass to the NHTSA VIN API.

  • build_vin_url() takes a single VIN in a character string and returns an appropriately-formatted url for a NHTSA API request via the /vehicles/DecodeVINValues/ endpoint.

  • build_vin_batch_url() takes up to 50 VINs in a character vector and returns appropriately-formatted url for a NHTSA API request via the /vehicles/DecodeVINBatchValues/ endpoint.

Usage

build_nhtsa_url(endpoint, format = "json", ...)

build_vin_url(vin, ...)

build_vin_batch_url(vin, ...)

Arguments

endpoint

a string containing the appropriate endpoint. Candidate endpoints can be found at https://vpic.nhtsa.dot.gov/api/

format

the file format to return from the API, one of 'json', 'xml', or 'csv'. Defaults to 'json'.

...

additional arguments to passed on to derived builder functions

vin

a string containing the VIN to query.

Value

  • build_nhtsa_url() returns a function which will in turn build a url which points to the specified endpoint on the NHTSA API

  • build_vin_url() returns a url as a string, formatted to query the NHTSA DecodeVinValues endpoint and decode a single VIN.

  • build_vin_batch_url() returns a url as a string, formatted to query the NHTSA DecodeVinBatch Values endpoint and decode multiple VINs in one call.

Examples

Run this code
# NOT RUN {
vin_url_xml <- build_nhtsa_url("/vehicles/DecodeVINValues/", format = "xml")
build_vin_url("3VWLL7AJ9BM053541")
build_vin_batch_url(c("3VWLL7AJ9BM053541", "JH4KA3140KC015221"))
# }

Run the code above in your browser using DataLab