Integration of new API endpoints (V2) #13
Replies: 4 comments 4 replies
-
For what it is worth, only few V2 endpoints actually exist. It is hard to tell from the web documentation alone, so I dug up routes.rb, which has roughly 240 lines of code for V1 endpoints, vs. about 20 for V2 endpoints. Another idea is to look at /app/controllers/api for endpoints that each version implements - where, again, the V1 subdirectory is much larger than V2. What that means is that a library user using some V2 endpoints couldn't use just the "V2 client", but would also need to use the separate(?) V1 client for the ~90% endpoints that don't yet have a V2 counterpart. In some of these cases, V1 and V2 endpoints seem to be at least compatible with each other, both as far as the necessary information to build either a V1 or a V2 query is concerned, and also concerning the returned data. For example, both versions of With all of that in mind, what about this: Idea 3: Mirror what Mastodon does, and use Semantic Versioning to notify library users without doing too much "magic"
This leaves the complication of the same version of this library potentially having to deal with different Mastodon server versions - but I think between
|
Beta Was this translation helpful? Give feedback.
-
I was thinking about this some more, and am currently wondering whether we need to lay some foundations for supporting instances on different server versions for our release 2.0.0, or if that can wait until later. I'm using View all followed tags and File a report as examples, because they have multiple changes in the version range that is relevant to us (current and last major, so anything >= 3.0.0). In our code to view all followed tags, we might want to do something along these lines:
Similarly, when filing a report:
Based on that, some follow-up questions:
|
Beta Was this translation helpful? Give feedback.
-
I'm copying parts a comment from #94 here, we should discuss whether we want a structure like that for our entities that come in V1 and V2 variants: For what it's worth, if we want to store either the V1 or V2 instance in our MastodonClient, then we would probably have to have an (abstract?) |
Beta Was this translation helpful? Give feedback.
-
Supporting different Mastodon server versions / API levels was brought up in #217 again. With some more months of both using Mastodon and implementing its APIs, at least my understanding of the whole situation has changed a bit: Mastodon version 3.0.0 was released in October 2019, nearly four years ago. Visiting different instances in the past months, I haven't found a single one that is running anything less than 4.0.0, let alone 3.0.0. If we keep our promise to support everything down to 3.0.0, we might find ourselves spending a lot of time on overcomplicating our codebase for something that won't ever be used. So, one thing we could consider would be to restrict our compatibility to "minor Mastodon server versions first released within the last X months, restricted to the current and last major version". For what it's worth, if Even picking a larger Last but not least, even if we want to keep supporting "the current and last version down to their first releases", we could choose to start this with the current version - so, keep supporting 4.x once 5.0 comes around, but not necessarily get everything in place for 3.x. That aside, I believe most of the other ideas in this discussion are still valid. Once we support different server versions with different capabilities that are not strictly backwards-compatible, we need to decide whether we want to make information about that available to library users, or whether it is sufficient to potentially throw a RequestException and let the library user deal with that. |
Beta Was this translation helpful? Give feedback.
-
Addition of Mastodon API V2 endpoints
Hello everyone,
During the last couple of days I was trying to find a way on how to add the new Mastodon V2 API endpoints to this library in a good way. The high-level plan is to build a library which supports the current and the previous Mastodon API versions (currently V1 and V2).
I have collected some thoughs on this and would be very happy to get some feedback from you. It is very well possible that some of my thoughts below do not make sense at all. So please correct me 😀 Happy to get some input from experienced developers.
Mastodon Server API
Mastodon4J Library
The current library targets V1 endpoints only. Also, not all of the V1 endpoints return all data possible. Some things are still missing. For example, in the call for fetching instance information a lot of data that is actually present, is not returned by the library.
Current Ideas
Idea 1: Library performs all the magic
The overall goal of this approach is to transform the different data models of Mastodon API V1 and V2 into some sort of unified data model that is presented to the library user. The user would not have to worry about which API version to call, as the library is doing this automatically (some sort of auto detection).
The unified data model would include:
Furthermore, when a library user wans to post a status for example, he would not need to worry about which API version he is targeting. That means a "post status" request for example would:
Pros:
Cons:
Idea 2: Let the user choose
The goal of this approach is to support the current and the previous Mastodon API versions in the library (at the moment, V1 and V2). Code for every API version would evolve in completely separate packages(v1.* and v2.*). The user would have to choose for himself, which API client to use (V1 or V2). To make things easier, an additional helper class could be added to detect the Mastodon API version.
In case of a new Mastodon API version, a new v3.* package structure would be introduced. Also, library users need to migrate their code slowly over to the new v3.* code. v1.* package structure would be removed from library.
Pros:
Cons:
Personal Opinion
At the moment I am favoring idea number 2, as it seems much more easier to maintain. The additional burden on the user side to decide whether to use V1 or V2 client seems to be acceptable. I think the approach in idea 1 is calling for trouble and complex scenarios. I rather have a client for every API version that returns a proper representation of the data that is currently there.
Beta Was this translation helpful? Give feedback.
All reactions