Enhance POST requests to /ask endpoint with JSON body parsing support #187
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
The
/ask
endpoint supported both GET and POST requests, but POST requests could only extract query parameters from the URL, not from JSON request bodies. When sending queries via POST withContent-Type: application/json
, the server would ignore the JSON body and only look for URL parameters, limiting proper REST API usage.Root Cause
The
WebServer.py
was only parsing URL query parameters for both GET and POST requests, but not processing JSON request bodies. This meant:✅ These worked before:
❌ This didn't work:
Solution
Enhanced POST request handling by adding JSON body parsing logic:
method == "POST"
andbody
existsquery
parameter from JSON and merge with existingquery_params
Technical Details
File Modified:
webserver/WebServer.py
Lines Added: 13 lines in the request handling section
Dependencies: Uses existing
json
module (no new dependencies)Testing
✅ Verified working with:
Test Commands:
Impact
Breaking Changes
None - this is purely additive functionality that enhances existing POST support without changing any current behavior.