-
Notifications
You must be signed in to change notification settings - Fork 3
Swift API for caling HTTP APIs with context #67
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
Swift API for caling HTTP APIs with context #67
Conversation
The option was for end-to-end tests on Linux. The option didn't work. Also we are not running those tests on Linux at the moment.
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These changes are made so that the Example app can work. I believe we want to remove these "legacy" API call functions, which will be done in separate PRs.
I just skimmed through the changes for now and noticed that this PR implements quite a bit of stuff for @crazytonyli Any chance this implementation could be based on If that's not possible, I have some ideas about how to at least contain it. So, let me know what you think! |
@oguzkocer This PR implements an API design that can be automatically added to all REST models. In my chat with @jkmassel, he wanted to see what's required to give a new model the same API design implemented in this PR. Since we have already a post implementation in the rust library, I used that as an example (see the "Support a new type" section in the PR description). I'm aware that we don't want to ship posts in 0.1. I'm okay with either reverting the posts changes in this PR or deleting the posts code entirely after this PR is reviewed and merged. The posts code in this PR is for demonstration after all. |
The parser functions are added in #84.
This PR supersedes #62 with a full support of accessing REST APIs with different context.
API design
All REST endpoints can be called using an
api: WordPressAPI
instance like this:Implementation
The above API is supported by a few namespace types.
When you call
.[users|posts|...]
, you get anAnyNamespace<T>
instance. If the REST resource model conforms toContextual
protocol, you can get thoseforViewing
,forEditing
,forEmbedding
functions which returns special namespace accordingly.At the moment all "contextual namespaces" can call
get(id:)
andlist()
functions. We can add more next.Some REST endpoints have more functions other than CRUD, like get current user. For those, we'll need to manually implement them under appropriate namespace types. For example:
wordpress-rs/native/swift/Sources/wordpress-api/Users/Users.swift
Lines 49 to 71 in 95225a7
Support a new type
When adding a new type to the library, we'll need to manual write two things to hook them up with the above API design (see this posts example).
Contextual
, whose implementation calls rust functions..[users|posts]
equivlant for the new type.Next steps
Currently only
get(id:)
andlist()
functions are shared among all REST models. We can add more, likecreate(params:)
,update(id:params:)
, anddelete(id:)
. Update: This is partly addressed in this PR: b935935When adding functions to namespace types, i.e. implementing
getCurrent
under all three context. It's not ideal that we have to repeat the same implementation three times. It'd be good to further extract to reduce boilerplate code. Update: This is now address in this PR: f96f8fc.