cyberpanel
cyberpanel copied to clipboard
[BUG] cloudAPI does not return valid JSON
When consuming cloudAPI endpoints, the expected response is valid JSON but CyberPanel is using an old method of returning responses using HttpResponse
and json.dumps(...)
which results in the actual response being of format text/html
instead of application/json
.
PROBLEM
This makes consuming the API cumbersome as data must be parsed into valid JSON in JavaScript using JSON.parse(...)
. This can lead to further issues as some of the responses must be parsed then parsed again to access the data properly which is also not desirable.
To Reproduce
- Consume any cloudAPI endpoint
- Observe that response is of type
text/html
instead ofapplication/json
Expected behavior
application/json
returned.
Screenshots (can also be viewed in the official CyberPanel API Documentation video @ https://youtu.be/HPCTDdEJ_gk?t=348)
CURRENT RESPONSE AS text/html
DESIRED RESPONSE AS application/json
Operating system: Irrelevant.
CyberPanel version:
Issue is present up to latest CyberPanel version i.e. CyberPanel Version 2.3 Build 4
Additional context
QUESTION: Is this behaviour intentional or can it be fixed?
SOLUTION: replace HttpResponse
with JsonResponse
and modify some views and JS accordingly.
I have prepared a Proof of Concept in this branch: https://github.com/xmok/cyberpanel/tree/return-json-in-cloudAPI EDIT: Link to comparison: https://github.com/usmannasir/cyberpanel/compare/v2.3.5-dev...xmok:cyberpanel:return-json-in-cloudAPI
If it looks desirable, I can turn it into a PR and work on migrating all the other endpoints as well. It will take time but can be accomplished.
Best!
@usmannasir, don't mean to bother you but could you review the above issue? I'll be willing to submit PRs if required but can't do it unless I have your go-ahead. Essentially, we'll replace HttpResponse
with JsonResponse
and slightly modify the code to account for the JSON file types. If required, we could also version the controller but isn't needed. Thanks!