r-lib / httr

httr: a friendly http package for R
https://httr.r-lib.org
Other
986 stars 1.99k forks source link

Default parsing of geojson with httr::content() #621

Closed lorenzwalthert closed 4 years ago

lorenzwalthert commented 5 years ago

Could we set the default handling for mime type "application/json+geo" to be the same as for "application/ json" so it does not need to be specified manually? Or even more general, does it make sense to strip away the "+..." always before deciding how to parse the output, so all "json+xyz" would fall back to "json"?

response <- httr::GET("https://api3.geo.admin.ch/rest/services/all/MapServer/identify?geometry=2679593.28515719,1249208.93603668&geometryType=esriGeometryPoint&layers=all:ch.are.bauzonen&mapExtent=312250,-77500,1007750,457500&imageDisplay=1391,1070,96&lang=de&tolerance=0&geometryFormat=geojson&sr=2056")
response
#> Response [https://api3.geo.admin.ch/rest/services/all/MapServer/identify?geometry=2679593.28515719,1249208.93603668&geometryType=esriGeometryPoint&layers=all:ch.are.bauzonen&mapExtent=312250,-77500,1007750,457500&imageDisplay=1391,1070,96&lang=de&tolerance=0&geometryFormat=geojson&sr=2056]
#>   Date: 2019-10-16 08:25
#>   Status: 200
#>   Content-Type: application/geo+json
#>   Size: 4.94 kB
#> <BINARY BODY>
head(httr::content(response))
#> [1] 7b 22 72 65 73 75
str(httr::content(response, as = "parsed", type = "application/json"), max.level = 3)
#> List of 1
#>  $ results:List of 1
#>   ..$ :List of 8
#>   .. ..$ geometry  :List of 2
#>   .. ..$ layerBodId: chr "ch.are.bauzonen"
#>   .. ..$ bbox      :List of 4
#>   .. ..$ featureId : int 18642
#>   .. ..$ layerName : chr "Bauzonen Schweiz (harmonisiert)"
#>   .. ..$ type      : chr "Feature"
#>   .. ..$ id        : int 18642
#>   .. ..$ properties:List of 9

Created on 2019-10-16 by the reprex package (v0.3.0)

hadley commented 4 years ago

Unfortunately I no longer believe that the autoparsing was a good idea, so I'm not adding new methods.