Skip to content

Improve how to create request URLs #181

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mfreiwald
Copy link
Contributor

@mfreiwald mfreiwald commented Jun 4, 2025

Description

There is a lot of duplicated code in all the ATProtoKit methods calling the API endpoints and I thought about simplify it, so changing the implementation should be easier if needed in the future.

This doesn't need to be the final implementation, it's just one way how to improve it.
What do you think about it?

Example

This is how you would create a requestURL:

let (authorizationValue, sessionURL) = try await prepareAuthorization(requiresAuth: false)

let queryURL = try await prepareRequest(sessionURL: sessionURL, endpoint: "/xrpc/app.bsky.graph.getFollowers") { queryItems in
    addQueryItem("actor", value: actorDID, to: &queryItems)
    addLimit(limit, to: &queryItems)
    addCursor(cursor, to: &queryItems)
}

Type of Change

  • Bug Fix
  • Enhancement
  • New Feature
  • Documentation

Checklist:

  • My code follows the ATProtoKit API Design Guidelines as well as the Swift API Design Guidelines.
  • I have performed a self-review of my own code and commented it, particularly in hard-to-understand areas.
  • I have made corresponding changes to the documentation.
  • My changes generate no new warnings or errors in the compiler or runtime.
  • My code is able to build and run on my machine.

@mfreiwald mfreiwald changed the title Make creating request simpler Improve how to create request URLs Jun 4, 2025
@MasterJ93
Copy link
Owner

MasterJ93 commented Jun 4, 2025

Yes, I have noticed that pattern as well for many (but not all) lexicon methods. I would be willing to accept a Pull Request. However, the only blocker at this moment is when I create the package for generated code. I want to be able to do it in such a way where the generator can easily notice that pattern and use that method. This doesn't mean I'm rejecting it: I just want to do this properly. That said, I don't exactly mind still accepting some form of implementation for now, and then when we cross that bridge of generated code, it can be changed.

Looking at how you've currently written it, it does seem to be a design that I actually like so far.

@MasterJ93
Copy link
Owner

Actually, looking at it further, this would help the generator more than it would hinder. Looks good all around so far!

@mfreiwald
Copy link
Contributor Author

Ok than I will finalise it 😊

and migration of all the methods can be done step by step.

Should this point to main or develop?

@MasterJ93
Copy link
Owner

This should go into develop, but I'm sure that this will take a while, and not all methods should be using this (some will have their lexicon models), so please take your time and don't use up too much of your spare time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants