developmentseed / developmentseed/stac-fastapi-html-middleware

Issue 1

Open
#1 0 comments 1 reaction 0 assignees View on GitHub
issue-1
Dominant language
HTML
Stars
8
Forks
1
PR merge metrics
No merged PRs in 30d

Description

## Background

in https://github.com/developmentseed/eoapi-devseed we've added custom HTML rendering for the STAC API. This meant re-writing most of the `Client` https://github.com/developmentseed/eoapi-devseed/blob/main/runtimes/eoapi/stac/eoapi/stac/client.py to:

- advertise both `f=html` or `accept` headers
- advertise HTML response type

It worked well but this is super custom and some users have expressed the need of the same feature for their own stac-fastapi instance.

In this repo, we will explore the creation of a starlette Middleware which could be added to any stac-fastapi application. The idea is to `intercept` the response and then check if `f=html` or `Accept: text/html` was provided in the request. If yes, then we encode the response into an HTML document.

Pros:
- No need to customize your client
- should work for any stac-fastapi application
- lightweight

Cons:
- ~~No OpenAPI advertising (for now)~~

```python
from starlette.middleware import Middleware

from stac_fastapi.api.app import StacApi
from stac_fastapi.html.middleware import HTMLRenderMiddleware

api = StacApi(
middlewares=[
Middleware(HTMLRenderMiddleware),
],
)
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.