Skip to content

Parse request bodies for PUT/PATCH/DELETE in local dev web action params#165

Merged
shazron merged 3 commits intomainfrom
copilot/fix-request-body-parsing
Apr 24, 2026
Merged

Parse request bodies for PUT/PATCH/DELETE in local dev web action params#165
shazron merged 3 commits intomainfrom
copilot/fix-request-body-parsing

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 22, 2026

Fixes #164

Local aio app dev behavior diverged from Adobe I/O Runtime by only parsing request bodies for POST. As a result, PUT, PATCH, and DELETE requests with bodies were not merged into action params (or encoded as __ow_body for raw actions).

  • Body parsing parity across HTTP methods

    • Updated createActionParametersFromRequest to process request bodies for post, put, patch, and delete instead of post only.
    • Existing content-type behavior is preserved:
      • non-raw actions: JSON / form-urlencoded bodies merge into params
      • raw actions: payload is serialized into __ow_body using existing logic
  • Regression coverage for affected methods

    • Added focused unit tests for PUT, PATCH, and DELETE in createActionParametersFromRequest:
      • non-raw + application/json → body fields merged into params
      • raw + application/json → body encoded into __ow_body
// before
if (params.__ow_method === 'post' && req.body !== null) { ... }

// after
if (['post', 'put', 'patch', 'delete'].includes(params.__ow_method) && req.body !== null) { ... }

Manual Testing

1. Check out the branch

git clone https://github.com/adobe/aio-cli-plugin-app-dev.git
cd aio-cli-plugin-app-dev
git checkout copilot/fix-request-body-parsing
npm install

2. Link the plugin locally via the Adobe I/O CLI

From the root of the checked-out branch, run:

aio plugins link .

Tip: The . refers to the root of the checked-out branch. After linking, aio will use this local build of the plugin instead of the published version. You can verify with aio plugins.

3. Create a test web action

In a new (or existing) aio app project, add a web action that echoes its params:

// actions/echo/index.js
async function main (params) {
  return { statusCode: 200, body: { received: params } }
}
module.exports = { main }

Declare it as a web action in app.config.yaml (e.g. web: 'yes').

4. Start the local dev server

aio app dev

5. Verify body parsing for PUT, PATCH, and DELETE

Replace <your-action-url> with the URL printed by aio app dev (e.g. https://localhost:9080/api/v1/web/<namespace>/<package>/echo).

# PUT with a JSON body
curl -sk -X PUT \
  -H "Content-Type: application/json" \
  -d '{"myField":"hello from PUT"}' \
  "<your-action-url>"

# PATCH with a JSON body
curl -sk -X PATCH \
  -H "Content-Type: application/json" \
  -d '{"myField":"hello from PATCH"}' \
  "<your-action-url>"

# DELETE with a JSON body
curl -sk -X DELETE \
  -H "Content-Type: application/json" \
  -d '{"myField":"hello from DELETE"}' \
  "<your-action-url>"

Expected: Each response should include "myField" with the value you sent (e.g. "hello from PUT").

Before this fix: params.myField would be undefined for all three methods.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 22, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copilot AI changed the title [WIP] Fix PUT/PATCH/DELETE request body parsing in local dev server Parse request bodies for PUT/PATCH/DELETE in local dev web action params Apr 22, 2026
Copilot AI requested a review from shazron April 22, 2026 09:10
github-actions[bot]
github-actions Bot previously approved these changes Apr 22, 2026
Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

🤖 PR Reviewer

The change extends body processing to include PUT, PATCH, and DELETE HTTP methods alongside POST, which is a correct and standards-compliant improvement. The implementation is clean and the tests adequately cover the new method cases. One minor note: DELETE with a body is technically allowed but uncommon; the current approach is still reasonable.

LGTM! This PR looks good to merge.


💡 How to re-trigger

Comment /review or /pr-reviewer on this PR

@shazron shazron marked this pull request as ready for review April 22, 2026 09:19
Comment thread src/lib/run-dev.js Outdated
Copilot AI requested a review from shazron April 22, 2026 09:27
Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

🤖 PR Reviewer

The change correctly expands HTTP method support for request body processing beyond POST to include PUT, PATCH, and DELETE, with appropriate use of optional chaining and case normalization. The tests cover the new methods well, though POST is notably absent from the methodsWithBody array used in parameterized tests (it's covered by existing dedicated tests). Overall the code is clean and the logic is sound.

LGTM! This PR looks good to merge.


💡 How to re-trigger

Comment /review or /pr-reviewer on this PR

@github-actions github-actions Bot dismissed their stale review April 22, 2026 09:29

Superseded by new review

@shazron shazron merged commit c937811 into main Apr 24, 2026
11 checks passed
@shazron shazron deleted the copilot/fix-request-body-parsing branch April 24, 2026 02:07
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.

Bug: PUT/PATCH/DELETE request body not parsed in local dev server (createActionParametersFromRequest)

3 participants