Re-architect Lemmy client (with support for v4) #30
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Alright, this PR is going to be a bit on the larger side, so buckle up! I’m leaving it in draft status for now while I gather more feedback and work on making it a bit more feature-complete.
Note
This only works with
v4
instances at the moment. Asv4
instances are not generally available yet, you will have toinitialize a new Lemmy instance using the current
main
branch on Lemmy.This re-architecture will first focus on
v4
compatibility. Support forv3
will likely also come, but only afterv4
ismore feature-complete.
Background
The initial goal of this PR was to add support for the
v4
version of the Lemmy API, which is expected to be introduced in v0.20.0. Thev4
version introduces significant changes to many of the existing endpoints to better align them with their respective domains and actions.Given these changes, I thought it would be a good opportunity to rethink how we’re handling our current client. My goal with this re-architecture is to make our client easier and more intuitive to use, as well as being able to better handle breaking changes to the Lemmy API.
Major Changes
Here are the main goals of this re-architecture:
lemmy.run()
and pass in theauth
token for every single request. Doing this feels a bit counter-intuitive, and I believe there are better methods for handling this.That said, this is still a work in progress, and I’m definitely open to suggestions and feedback from everyone! This re-architecture is partially inspired by PRAW (a Reddit Python API).
Examples
To give an example of how the new experimental client works in practice, I'll run through a few types of scenarios.
Client initialization
To initialize the client, we simply have to specify a few parameters, the only one that is required is the
instance
as all other parameters will have a default value or be optional (e.g,auth
)When a new client is initialized, it will automatically fetch the relevant Site and Account information (when a valid
auth
token is passed in). Once the client is initialized, all future requests will use the providedauth
token if applicable.auth
for every single requestFetching Feeds
To fetch posts for a given feed (e.g., all, local, subscribed, moderator), we can do the following:
Work Left
There is still a lot of work left for this re-architecture. However, I thought I'd create a draft PR for this in order to get some additional feedback on these overall changes.
If we do decide to migrate to this re-architecture, then it will be a while before it's completed as I have to add additional methods to perform actions (e.g., search, moderator actions, etc) and add compatibility with the
v3
API. Additionally, we'll have to make changes to Thunder to make it compatible with this re-architecture!Additional note: The API changes follow this commit from lemmy_js_client:
c59d755070f437ca38fcfc2191fb0a5a6b037965