Skip to content

Conversation

@vincentsarago
Copy link
Member

This PR does:

  • adds csv and geojson-seq outputs to GET - /items, GET - /search and POST - /search
  • refactor client to avoid using super() method (because the origin method can return JSONResponse directly)

For csv and geojson-seq (considered as programatic access) we add the pagination links in the Headers following https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Link 👇

curl http://127.0.0.1:8081/search\?limit\=1\&fields\=properties.datetime --header "Accept: text/csv" -v
*   Trying 127.0.0.1:8081...
* Connected to 127.0.0.1 (127.0.0.1) port 8081
> GET /search?limit=1&fields=properties.datetime HTTP/1.1
> Host: 127.0.0.1:8081
> User-Agent: curl/8.4.0
> Accept: text/csv
> 
< HTTP/1.1 200 OK
< date: Sun, 16 Feb 2025 15:49:57 GMT
< server: uvicorn
< content-disposition: attachment;filename=items.csv
< link: <http://127.0.0.1:8081/search?limit=1&fields=properties.datetime&token=next:MAXAR_Nepal_Earthquake_Nov_2023:44_120220012023_10300100F0446700>; rel="next"
< content-type: text/csv; charset=utf-8
< Transfer-Encoding: chunked
< 
itemId,collectionId,datetime
44_120220012023_10300100F0446700,MAXAR_Nepal_Earthquake_Nov_2023,2023-11-09T05:04:10Z

Sadly there is no specification for POST request pagination links so we might need to come up with something 🤷

# Items might not be a valid STAC Item objects
if fields := getattr(search_request, "fields", None):
if fields.include or fields.exclude:
return JSONResponse(item_collection) # type: ignore
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We HAVE to re-write the whole method in our custom runtime because if a user passed fields= then the orignal method was returning a JSONResponse, which would then need to be parsed back if we wanted to return an HTML response

if link
]
)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

curl --request POST http://127.0.0.1:8081/search --json '{"limit": 1, "token": "next:MAXAR_Nepal_Earthquake_Nov_2023:44_120220012023_10300100F0446700"}' --header "Accept: application/geo+json-seq" -v 
Note: Unnecessary use of -X or --request, POST is already inferred.
*   Trying 127.0.0.1:8081...
* Connected to 127.0.0.1 (127.0.0.1) port 8081
> POST /search HTTP/1.1
> Host: 127.0.0.1:8081
> User-Agent: curl/8.4.0
> Accept: application/geo+json-seq
> Content-Type: application/json
> Content-Length: 94
> 
< HTTP/1.1 200 OK
< date: Tue, 18 Feb 2025 19:37:04 GMT
< server: uvicorn
< content-disposition: attachment;filename=items.geojson
< pagination-token: <next:MAXAR_Nepal_Earthquake_Nov_2023:44_120220012022_10300100F0446700>; rel="next",<prev:MAXAR_Nepal_Earthquake_Nov_2023:44_120220012022_10300100F0446700>; rel="previous"
< content-type: application/geo+json-seq
< Transfer-Encoding: chunked

I went ahead and invented an header format for the token 😂

MimeTypes.geojson.value: {},
MimeTypes.html.value: {},
MimeTypes.csv.value: {},
MimeTypes.geojsonseq.value: {},

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL 🙇🏼

"content": {
MimeTypes.geojson.value: {},
MimeTypes.csv.value: {},
MimeTypes.geojsonseq.value: {},

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Next step, stac-geoparquet!

"model": api.ItemCollection,
},
},
response_class=GeoJSONResponse,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does this interact with a CSV response?

@vincentsarago vincentsarago merged commit cb5e1ef into main Feb 19, 2025
2 checks passed
@vincentsarago vincentsarago deleted the feature/more-output-format branch February 19, 2025 15:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants