Skip to content
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

API Client #25

Merged
merged 7 commits into from
Sep 9, 2024
Merged

API Client #25

merged 7 commits into from
Sep 9, 2024

Conversation

psrpinto
Copy link
Member

@psrpinto psrpinto commented Sep 5, 2024

This PR makes it possible to make requests to the WP REST API through an ApiClient object, that is available on every screen, through the session context:

const { session, apiClient } = useSessionContext();

const posts = await apiClient.getPosts();

Screen capture

In the screen capture below, "Hello world!" is the title of the post, which has been fetched from the REST API.

Screen.Recording.2024-09-09.at.11.16.10.mov

@psrpinto psrpinto self-assigned this Sep 5, 2024
@psrpinto psrpinto marked this pull request as ready for review September 9, 2024 10:19
Copy link
Member

@akirk akirk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! I tried it and it works like in the screen recording. Two thoughts:

@psrpinto
Copy link
Member Author

psrpinto commented Sep 9, 2024

I am curious why the post "Hello World" exists given that we have a step to delete all posts. Is it not executed?

That step got lost when I moved the previous code to the poc/ directory (the file you link is in that directory). I will bring that step back in this PR.

That you're querying the REST API of Playground is just a proof of concept, right? We'd usually POST there.

Yep, correct, the getPosts() was just a proof of concept, we probably won't be calling it.

@akirk
Copy link
Member

akirk commented Sep 9, 2024

That step got lost when I moved the previous code to the poc/ directory (the file you link is in that directory). I will bring that step back in this PR.

Oh, I missed that this was in the poc directory. We should delete it and rather create a poc tag back in history.

@psrpinto
Copy link
Member Author

psrpinto commented Sep 9, 2024

I will merge this as is, and I will delete the poc/ directory, and bring back the steps to delete posts in another PR.

@psrpinto psrpinto merged commit 59ac810 into trunk Sep 9, 2024
1 check passed
@psrpinto psrpinto deleted the api-client branch September 9, 2024 15:00
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