Skip to contents

Perform both a single request and multiple requests to BPS API.

  • bps_request() sends a single request

  • bps_request_multiple() sends multiple requests with multiple query parameters to one endpoint at a time

  • bps_request_paginated() sends multiple requests to multiple pages to the list endpoint

Usage

bps_request(url_path, ...)

bps_request_multiple(url_path, query_params)

bps_request_paginated(url_path, ..., page = 1)

Arguments

url_path

The path component of the URL. Must be either "domain", "list", "view", "dataexim" or "interoperabilitas".

...

Name-value pairs that provide query parameters. See httr2::req_url_query() for more details.

query_params

A list of name-value pairs that provide query parameters.

page

The page number of the result. Defaults to page one. Set to Inf to request all pages.

Value

  • bps_request() returns a list with the bpsr_response class.

  • bps_request_multiple() and bps_request_paginated() return a list with the bpsr_multiple_responses class.

Examples

# Request a list of domains of every BPS bureau
bps_request("domain", type = "all")
#> <bpsr_response>
#> Content:
#> List of 3
#>  $ status           : chr "OK"
#>  $ data-availability: chr "available"
#>  $ data             :List of 2
#>   ..$ :List of 3
#>   .. ..$ page : int 1
#>   .. ..$ pages: int 1
#>   .. ..$ total: int 549
#>   ..$ :'data.frame':	549 obs. of  3 variables:
#>   .. ..$ domain_id  : chr [1:549] "0000" ...
#>   .. ..$ domain_name: chr [1:549] "Pusat" ...
#>   .. ..$ domain_url : chr [1:549] "http://www.bps.go.id" ...

# Request a list of dataset subjects on each domain on different pages
bps_request_multiple(
  "list",
  list(
    model = "subject",
    domain = c("0000", "1100", "1500"),
    page = c(1, 2, 1),
    lang = "eng"
  )
)
#> <bpsr_multiple_responses>
#> Status:
#> • OK: 3
#> • Error: 0
#> Data availability:
#> • Available: 3
#> • Not available: 0
#> Contents:
#> List of 3
#>  $ :List of 3
#>   ..$ status           : chr "OK"
#>   ..$ data-availability: chr "available"
#>   ..$ data             :List of 2
#>   .. ..$ :List of 5
#>   .. ..$ :'data.frame':	10 obs. of  5 variables:
#>  $ :List of 3
#>   ..$ status           : chr "OK"
#>   ..$ data-availability: chr "available"
#>   ..$ data             :List of 2
#>   .. ..$ :List of 5
#>   .. ..$ :'data.frame':	10 obs. of  5 variables:
#>  $ :List of 3
#>   ..$ status           : chr "OK"
#>   ..$ data-availability: chr "available"
#>   ..$ data             :List of 2
#>   .. ..$ :List of 5
#>   .. ..$ :'data.frame':	10 obs. of  5 variables:

# Request the complete list of dataset subjects on the central bureau's
# domain
bps_request_paginated(
  "list",
  model = "subject",
  domain = "0000",
  lang = "eng",
  page = Inf
)
#> <bpsr_multiple_responses>
#> Status:
#> • OK: 5
#> • Error: 0
#> Data availability:
#> • Available: 5
#> • Not available: 0
#> Contents:
#> List of 5
#>  $ :List of 3
#>   ..$ status           : chr "OK"
#>   ..$ data-availability: chr "available"
#>   ..$ data             :List of 2
#>   .. ..$ :List of 5
#>   .. ..$ :'data.frame':	10 obs. of  5 variables:
#>  $ :List of 3
#>   ..$ status           : chr "OK"
#>   ..$ data-availability: chr "available"
#>   ..$ data             :List of 2
#>   .. ..$ :List of 5
#>   .. ..$ :'data.frame':	10 obs. of  5 variables:
#>  $ :List of 3
#>   ..$ status           : chr "OK"
#>   ..$ data-availability: chr "available"
#>   ..$ data             :List of 2
#>   .. ..$ :List of 5
#>   .. ..$ :'data.frame':	10 obs. of  5 variables:
#>  $ :List of 3
#>   ..$ status           : chr "OK"
#>   ..$ data-availability: chr "available"
#>   ..$ data             :List of 2
#>   .. ..$ :List of 5
#>   .. ..$ :'data.frame':	10 obs. of  5 variables:
#>  $ :List of 3
#>   ..$ status           : chr "OK"
#>   ..$ data-availability: chr "available"
#>   ..$ data             :List of 2
#>   .. ..$ :List of 5
#>   .. ..$ :'data.frame':	10 obs. of  5 variables: