-
Notifications
You must be signed in to change notification settings - Fork 102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Generate links in api layer #472
[WIP] Generate links in api layer #472
Conversation
A few ideas for differentiating between links:
{
"rel": "next",
"type": "application/geo+json",
"method": "GET",
"href": "/search?token=12345",
"inferred": false,
}
Third bullet is my preference. Note that I haven't thought too much about how children/browsable conformance plays into this as we haven't implemented it yet. Link ResolutionBackends need to return absolute links when referencing external resources like licenses or citations. We must distinguish these links from relative links. Using from urllib.parse import urlparse
>>> urlparse("/collections")
ParseResult(scheme='', netloc='', path='/collections', params='', query='', fragment='')
>>> urlparse("s3://bucket/key_prefix/object.txt")
ParseResult(scheme='s3', netloc='bucket', path='/key_prefix/object.txt', params='', query='', fragment='')
>>> urlparse("https://science.nasa.gov/earth-science/earth-science-data/data-information-policy")
ParseResult(scheme='https', netloc='science.nasa.gov', path='/earth-science/earth-science-data/data-information-policy', params='', query='', fragment='') |
I definitely agree with the third option using precedence. The other thought I had related to ability to control extensions that add additional links is to use the request.scope['routes'] and request.scope['route'] to introspect the App (same as how the OpenAPI docs are created - and there are some examples there that we could use) and to include any links that are at the next level up as the "self" link. This would mean that when requesting "/" endpoint, that it should auto-discover the "/conformance" endpoint and that it would be able to scan the routes and if the FiltersExtension was enabled, it would also find the "/queryables" endpoint. The mime_type would be able to be found on the response_class. |
I think this is a really good idea, I can play around with it in another PR. |
Closing as OBE #555. |
Related Issue(s):
Description:
Moves link generation into the API layer to create better separation of concerns between API/backend libraries. Links are split into two categories:
self
,root
,parent
,child
etc.) are dynamically generated by the API layer based on the request path and the stac object returned by that request.next
,prev
, links to external resources etc.) may be returned by backend implementations and resolved by the API layer -urljoin(base_url, link['href'])
. The current landing page is a good example of this; links to children collections are generated by the backend (Backend.all_collections
) and resolved by the API layer. This allows backends to return their own links, and makes it easy for users of those backends to extend this behavior.With this PR the starlette request object is no longer passed to the backend client as a key word argument and
core.py
no longer imports HTTP specific things likeurllib.parse.urljoin
,fastapi.Request
, andstac_fastapi.types.request.get_base_url
.TODOs
PR Checklist:
pre-commit run --all-files
)make test
)make docs
)