-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
API: return the api_version
on the response
#10276
Conversation
This new header will force the API endpoint to return a specific JSON version schema without taking into consideration the any other header. The idea behind this is to allow theme authors guarrantees about the JSON scheme they are expecting; without stopping us to move forward with potential changes required to the API response when adding new features/addons/etc. Related readthedocs/addons#64
@agjohnson I implemented the new header to support the work done in readthedocs/addons#64. While I was working on this, I thought that maybe we don't want to do two requests and instead we only want to do one and return both JSON structures in the same response. So, when our JS client asks for the v1 of the JSON and the theme author asks for the v0 of it, I'm thinking we could return something like the following and put {
"0": { }, // ... structure for the v0 of the JSON ...
"1": { }, // ... structure for the v1 of the JSON ...
} The potential downside that I see here is dealing with invalid API versions specified by the theme authors and also error handling. I think there are some trade offs here, but I wanted to mention it because maybe we can discuss it a little more and decide if it's a good idea or not. In any case, I think it's an implementation detail and we can improve its performance later since the JS code is encapsulated. |
Hrm, I guess it's not clear what the case would be for our JS asking for a different version than what the theme author is asking for. Shouldn't these always be the same version? That is, shouldn't our addon library inspect what version is defined in a meta tag before requesting the API data? |
The idea behind this work is to allow us to keep adding addons, update them, make breaking changes to the API response, etc -- but keeping theme author integrations working properly. This is, our latest js client may require v3 of the API response but the theme integration may still be using v1. Basically, our js client is independent from the theme integration. |
I agree on versioning the API response, but I was instead asking why our library would ever request a v3 API response when the theme defined a requirement for a v1 API response. Shouldn't our library only request the v1 API response? It seems like this is trying to cover the use case where a theme/doc author is both using our API directly and using our built in elements. Is that correct? I guess I have questions:
|
Really good questions. Let's see if I can clarify what's in my head and why I went this way. I started this work because of the conversation we had with Eric at PyCon, so you are missing some context here. Again, I'm not saying this implementation/pattern is the correct; but it's what I understood from that talk. The main goal here is to provide theme authors a way to use the JSON schema in a stable way (this is the I think this scenario will be the second most used case where users use a theme that uses our API response in a custom way to make the theme a little nicer. However, our flyout/toolbar/dashboard is always injected with all our latest addons. Answering the specific questions:
Yes. I think this is going to be the second most used case. I think about integrating the version selector into the theme, but do not overriding the PR and non latest version notification at all.
I don't think so. I want our js client to always be the latest one with all the newest features. This allow us to broadly deploy bugfixes, new addons and more to all our users without breaking theme integrations that may rely on an older API data response. Let's say that we create a new addon that shows a new notification and requires v2 of the API data response. We deploy the newest js client. It will request v2 for its own usage and also v1 for the theme integrations to keep working without breaking.
I don't think so. We always want to show our own flyout/dashboard/toolbar (see readthedocs/addons#53) with all our addons. This is what we called at PyCon "the Read the Docs unified experience" Does this help to clarify the vision/idea/path forward that we are proposing here? |
…mitos/api-hosting-version
After doing a POC 🧪 that uses the As a theme author, you should:
As Read the Docs developers, this allow us:
As a small example, let's say the theme author integrates the flyout sections separately: the language selector is at the top right and the version selector is at the top left in the navbar (just to mention something) by using the APIv1 JSON structure. All the other addons are kept with their default values and no extra integrations/modifications are done. After some time, we found an issue in the flyout addons that require some breaking changes on its JSON structure and we want to fix it. We make them, create APIv2 JSON structure and update our At this point, when the theme that integrates the flyout is loaded, our In the future, if the theme author wants, they can update its meta tag to be |
…mitos/api-hosting-version
X-RTD-Hosting-Integrations-API-Version
api_version
on the response
I changed the title because the The only thing that was not implemented there was returning the |
By the way, this plan makes a lot of sense so far. I think you are correct in serving a static version of the addons JS, but with a variable data structure. We'll have to see what weird things theme authors start doing with our addons eventually, but I suspect it won't be a problem for theme authors to rely on just the data structure. I'm thinking that if we do need to allow theme authors access to the addons API (not just the data structure) they should pin our library and bundle the functions they need into their own JS. We'd still inject and use the latest addons JS though. That's something we can cross later, I don't see a strong need for this yet. |
This new header will force the API endpoint to return a specific JSON version schema without taking into consideration the any other header.
The idea behind this is to allow theme authors guarrantees about the JSON scheme they are expecting; without stopping us to move forward with potential changes required to the API response when adding new features/addons/etc.
Related readthedocs/addons#64