CMU-CREATE-Lab / esdr

Environmental Sensor Data Repository (ESDR)
Other
12 stars 9 forks source link

Add option to get feed metadata as CSV #61

Closed chrisbartley closed 3 years ago

chrisbartley commented 3 years ago

Some users want feed metadata as CSV instead of JSON. Add a format query string option to the feed metadata API. Defaults to JSON, but will accept csv (case insensitive) for CSV output of the metadata. Similar in spirit to the format option for export. More detail...

Currently, calling this:

http://esdr.cmucreatelab.org/api/v1/feeds/?fields=id,name,latitude,longitude&where=productId=69&limit=3&orderBy=id

Will return something like this:

{
   "code" : 200,
   "status" : "success",
   "data" : {
      "totalCount" : 48002,
      "rows" : [
         {
            "id" : 12668,
            "name" : "AQMD_NASA_17 B PurpleAir",
            "latitude" : 34.062618,
            "longitude" : -118.247131
         },
         {
            "id" : 12669,
            "name" : "AQMD_NASA_18 PurpleAir",
            "latitude" : 34.138439,
            "longitude" : -118.13797
         },
         {
            "id" : 12670,
            "name" : "AQMD_NASA_18 B PurpleAir",
            "latitude" : 34.138439,
            "longitude" : -118.13797
         }
      ],
      "offset" : 0,
      "limit" : 3
   }
}

This issue requests to extend the API so that calling this (note the addition of &format=csv at the end):

http://esdr.cmucreatelab.org/api/v1/feeds/?fields=id,name,latitude,longitude&where=productId=69&limit=3&orderBy=id&format=csv

would return this:

id,name,latitude,longitude
12668,AQMD_NASA_17 B PurpleAir,34.062618,-118.247131
12669,AQMD_NASA_18 PurpleAir,34.138439,-118.13797
12670,AQMD_NASA_18 B PurpleAir,34.138439,-118.13797

Things to deal with:

chrisbartley commented 3 years ago

Fixed in commit bd5e7ad9. Just append format=csv to the query string when requesting feed(s) metadata. See the HOW TO for details and examples.