-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
Currently, the Step class's HTTP methods (POST, PUT, PATCH) only accept string body parameters. This feature request proposes changing these methods to accept array parameters instead, with automatic conversion to the appropriate string format based on the Content-Type header.
// Current approach requires manual conversion
$data = ['name' => 'John', 'age' => 30];
$step->header('Content-Type', 'application/json')
->post('http://example.com', json_encode($data));The solution
Change the body parameter in HTTP methods to accept arrays instead of strings, with automatic conversion based on the Content-Type header:
// Proposed solution
$step->header('Content-Type', 'application/json')
->post('http://example.com', [
'name' => 'John',
'age' => 30
]);
// For form data
$step->header('Content-Type', 'application/x-www-form-urlencoded')
->post('http://example.com', [
'username' => 'john_doe',
'password' => 'secret'
]);The conversion would be handled automatically:
- application/json → JSON encoded string
- application/x-www-form-urlencoded → URL-encoded query string
- Default to JSON if no Content-Type is specified
Alternative
- Create separate methods for different content types (postJson, postForm, etc.)
- Accept both string and array parameters using union types
- Add a separate body formatter class/trait
Additional context
This would be a breaking change for existing code that passes string bodies directly. Implementation would require updates to:
src/Step.php- Associated test files
- Documentation
Metadata
Metadata
Assignees
Labels
No labels