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

Support for POST requests #3185

Open
fluiddot opened this issue Feb 22, 2021 · 1 comment
Open

Support for POST requests #3185

fluiddot opened this issue Feb 22, 2021 · 1 comment
Labels
[Type] Enhancement Improves a current area of the editor

Comments

@fluiddot
Copy link
Contributor

Motivation

POST requests are not currently supported in the React native Gutenberg bridge and they're required by the Reusable block for updating its content.

Solution

As we do for GET requests, we could follow a similar approach by having specific logic for managing this type of request.

Changes in the bridge

For helping understanding the changes that would involve handle POST requests I described for each platform how a request is currently made.

iOS

Here I detailed the flow when a request is made from the RN to iOS side:

For supporting POST requests the idea here is first to identify the type of the request and depending on that invoke the bridge method, fetchGetRequest for GET and fetchPostRequest for POST. This change is already implemented in this draft PR.

Android

For Android we could follow the same approach, here is the flow when a request is made from RN to Android side:

This part is not implemented yet.

Extra implementations for iOS

I spotted while I was testing that POST requests were not available for self hosted sites. Looks like most of the requests on those sites go through the XMLRPC API instead the Rest API. For this purpose I created a PR in WordPressKit-iOS for supporting POST requests via Rest API.

Extra implementations for Android

On Android most of the network request logic is managed by FluxC, I checked that there’s a specific store for React native but doesn’t provide functionality for POST requests so this part should be implemented.

Alternatives

As far as I know there're no alternatives related to this problem, Reusable blocks are hidden post types (wp_block) that require a POST request to update its content.

Additional context

We have to add support for all the different site scenarios:

  • WP.com regular site
  • Atomic site
  • Self-hosted without Jetpack
  • Self-hosted with Jetpack
@fluiddot
Copy link
Contributor Author

fluiddot commented Feb 22, 2021

How to test POST requests

Since the only part that requires this type for requests for now is the Reusable block, I added a basic flow for editing them through an edit/save button embedded in the block.

The changes can be found in a branch in Gutenberg repository named rnmobile/try/reusable-block-post-requests.

How to apply it

The easiest way to apply the changes for testing is by cherry-picking the changes from commit 5b905d8b6aeff1a44ed6743165f30077aa3acc0c to the working branch without committing the changes. Once the work is done those changes should be discarded and not pushed.

Testing steps

It's highly recommended to connect the device/simulator to Charles proxy to inspect the network requests.

In the web version

  1. Open a post.
  2. Select some blocks and create a reusable block.
  3. Save the post.

In the mobile version

  1. Open the previous post.
  2. Select the reusable block.
  3. Tap on the "Edit" button.
  4. Modify the content of the reusable block.
  5. Tap on the "Save" button.
  6. Observe that a POST request is made to the endpoint wp/v2/blocks/<REUSABLE_BLOCK_ID> with the modified content.
  7. Observe that the reusable block gets updated with the new content.
  8. Close the post and open it again.
  9. Observe that the reusable block renders the new content.

@fluiddot fluiddot self-assigned this Feb 22, 2021
@fluiddot fluiddot removed their assignment Feb 3, 2023
@fluiddot fluiddot added [Type] Enhancement Improves a current area of the editor and removed [Type] Task labels Feb 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Enhancement Improves a current area of the editor
Projects
None yet
Development

No branches or pull requests

2 participants