Body Parameters
Learn how to work with body parameters (JSON, form data) in moclojer. Access data from the request body in POST, PUT, and PATCH.
What Are Body Parameters?
# Example of POST with JSON in body
curl -X POST http://localhost:8000/users \
-H "Content-Type: application/json" \
-d '{
"name": "John Doe",
"email": "[email protected]",
"age": 30
}'Why Use Body Parameters?
Accessing Body Parameters
Syntax: {{json-params.field}}
{{json-params.field}}Content-Type: application/json
Simple JSON
Nested Objects
Arrays in Body
Data Types
Strings
Numbers (no quotes!)
Booleans
Null
Combining Parameters
Body + Path Parameters
Body + Query Parameters
Body + Headers
Practical Use Cases
1. Create User (POST)
2. Update Profile (PATCH)
3. Login (Authentication)
4. Create Order (E-commerce)
5. Upload Metadata (without binary file)
Validation and Errors
Required Fields (Simulation)
Invalid Types
Invalid Email
Content-Type: application/x-www-form-urlencoded
Best Practices
β
Do
β Avoid
Troubleshooting
Problem: Template is not replaced
Problem: Number comes as string
Problem: Nested object doesn't work
Problem: "Unexpected end of JSON"
Next Steps
See Also
Last updated
Was this helpful?