Skip to content

Conversation

@waleedlatif1
Copy link
Collaborator

@waleedlatif1 waleedlatif1 commented Aug 19, 2025

Summary

add native support for form-urlencoded inputs into API block

Type of Change

  • New feature

Testing

Tested the same request here & in postman, ensured that the responses were identical

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

Screenshots:

Before (even adding content-type to application/x-www-form-urlencoded it still used application/json):
Screenshot 2025-08-19 at 12 28 18 PM

After (respects the users content-type, converts json body into url encoded entry):
Screenshot 2025-08-19 at 12 28 01 PM

@vercel
Copy link

vercel bot commented Aug 19, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
sim Ready Ready Preview Comment Aug 19, 2025 7:31pm
1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
docs Skipped Skipped Aug 19, 2025 7:31pm

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

Greptile Summary

This PR adds native support for application/x-www-form-urlencoded content type to the API block, enabling users to make form-encoded requests without manual string formatting. The implementation spans four main areas:

HTTP Request Tool Enhancement: Modified apps/sim/tools/http/request.ts to automatically convert JSON object bodies to URL-encoded strings when the Content-Type header is set to application/x-www-form-urlencoded. The tool now checks for user-defined Content-Type headers and only defaults to application/json when none is specified, maintaining backward compatibility.

Body Processing Logic: Updated apps/sim/tools/utils.ts to improve the formatRequestParams function's handling of preformatted content types. The key change replaces bodyResult.body with typeof bodyResult === 'string' check, ensuring that string responses from form-urlencoded and NDJSON content types are passed through directly without JSON stringification.

Test Infrastructure Alignment: Modified apps/sim/tools/__test-utils__/test-tools.ts to mirror the production body processing logic, ensuring the ToolTester correctly handles preformatted content types during testing without double-encoding already formatted strings.

Comprehensive Test Coverage: Added extensive test cases in apps/sim/tools/http/request.test.ts covering custom Content-Type handling, OAuth client credentials flows, and form-urlencoded POST requests. Updated existing tests in apps/sim/tools/utils.test.ts to align with the new direct string return pattern for body functions.

The changes integrate seamlessly with the existing tool architecture, leveraging the same content-type detection patterns used for NDJSON and maintaining consistency across the codebase's request handling mechanisms.

Confidence score: 4/5

  • This PR is safe to merge with minimal risk as it primarily adds new functionality while maintaining backward compatibility
  • Score reflects well-structured changes with comprehensive test coverage, though the body processing logic changes in core utilities require careful validation
  • Pay close attention to apps/sim/tools/utils.ts and apps/sim/tools/http/request.ts for proper form-urlencoded handling

5 files reviewed, 2 comments

Edit Code Review Bot Settings | Greptile

@waleedlatif1 waleedlatif1 merged commit 2009901 into staging Aug 19, 2025
5 checks passed
@waleedlatif1 waleedlatif1 deleted the fix/api branch August 19, 2025 19:32
Sg312 pushed a commit that referenced this pull request Aug 20, 2025
arenadeveloper02 pushed a commit to arenadeveloper02/p2-sim that referenced this pull request Sep 19, 2025
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.

1 participant