JSON-formatted '/status' API response + generic cleanup#3038
Conversation
|
@sdargoeuves @captainpacket -- here's the API implementation of "netlab status" as a usable data structure. I also did a bit of a cleanup, hopefully resulting in a more generic "get" method that can handle multiple multi-part requests. I wanted to retain the "old" /status results in case anyone already uses them, so you get the JSON data structure back only with "/status/json" or "/status/json/instance". I would love to have a better idea how to handle that. Any suggestions? |
There was a problem hiding this comment.
Pull request overview
This PR adds JSON-formatted responses to the /status API endpoint and refactors the API request handler routing logic for better maintainability.
Changes:
- Added generic
send_replyandsend_errorhelper functions for consistent response handling - Enhanced
/statusendpoint to support JSON output and instance-specific queries - Refactored GET request routing to use separate handler dictionaries for simple and path-based endpoints
- Updated default bind address to use
external_commands.get_local_addr()instead of hardcoded localhost - Added KeyboardInterrupt handling and improved server startup logging with protocol information
The /status API call can now return usable JSON data
Lacking any better ideas, I went for the query string (having "json" in URL seemed awkward) with an environment variable as a fallback mechanism (and "json" as default). This allows an implementations to set an environment variable before starting the API server to keep using the old API format . |
The /status API call can now return usable JSON data