Improve how to create request URLs
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
- [x] Enhancement
- [ ] New Feature
- [ ] Documentation
Checklist:
- [x] 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.
- [x] My changes generate no new warnings or errors in the compiler or runtime.
- [x] My code is able to build and run on my machine.
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.
Actually, looking at it further, this would help the generator more than it would hinder. Looks good all around so far!
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?
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.