geobeyond / Arpav-PPCV-backend

Backend di Piattaforma Proiezioni Climatiche per il Nord-Est.
Creative Commons Attribution 4.0 International
0 stars 1 forks source link

Return GeoJSON FeatureCollection from stations list API endpoint #67

Closed ricardogsilva closed 5 months ago

ricardogsilva commented 5 months ago

This PR changes the default response type of /api/v2/observations/stations (AKA the stations list endpoint) to be a GeoJSON feature collection.

The proposed implementation makes the default response media type be application/geo+json. It is still possible to get the previous response type by simply passing the accept header Accept: application/json - we can decide later if it is worth keeping the plain JSON response or just have the GeoJSON.

The response payload is modeled after the response produced by pygeoapi's collection items endpoint for OGC API Features, with some small tweaks:

Example request using the httpie client (the limit query parameter is passed just for getting a small response that I can paste here:

http localhost:5001/api/v2/observations/stations limit==2

and corresponding response

{
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "geometry": {
        "type": "Point",
        "coordinates": [
          12.28232702,
          45.88132477
        ]
      },
      "properties": {
        "code": "100",
        "name": "Conegliano",
        "type_": "agro",
        "altitude_m": 90
      },
      "id": "4eb8a422-22f1-4bd5-827d-763ba84891f0",
      "links": [
        "http://localhost:5001/api/v2/observations/stations/4eb8a422-22f1-4bd5-827d-763ba84891f0"
      ]
    },
    {
      "type": "Feature",
      "geometry": {
        "type": "Point",
        "coordinates": [
          12.36910037,
          44.9173386
        ]
      },
      "properties": {
        "code": "101",
        "name": "Porto Tolle - Pradon",
        "type_": "agro",
        "altitude_m": -3
      },
      "id": "72d079c3-b071-4e31-87e7-bcebafc0d220",
      "links": [
        "http://localhost:5001/api/v2/observations/stations/72d079c3-b071-4e31-87e7-bcebafc0d220"
      ]
    }
  ],
  "links": {
    "self": "http://localhost:5001/api/v2/observations/stations?limit=2&offset=0",
    "next": "http://localhost:5001/api/v2/observations/stations?limit=2&offset=2",
    "previous": null,
    "first": "http://localhost:5001/api/v2/observations/stations?limit=2&offset=0",
    "last": "http://localhost:5001/api/v2/observations/stations?limit=2&offset=182"
  },
  "number_matched": 182,
  "number_total": 182,
  "number_returned": 2
}