Skip to content

Conversation

@tonyfettes
Copy link
Contributor

Motivation

The cmd/server predates the httpx package, and have many utility types, functions that are already implemented in package httpx. Also, routing using pattern matching creates deep nesting code level, making it hard to read & understand.

Changes

This PR uses Router types & methods from httpx package to refactor the cmd/server package to use it for routing HTTP request. Such refactor greatly reduced the nesting level of the code, improved the overall readability. Also, this PR replace the private JsonError defined in cmd/server with the one in httpx for early exiting and error-reporting. Additionally, this PR changes the hard-coded HTTP status code to use constants defined in httpx/status, eliminating the pass of the reason argument, making the HTTP server hebaves more consistently and reduce possibility of human error by mismatching reason string and status code.

@tonyfettes tonyfettes force-pushed the haoxiang/refactor-server-to-use-httpx-router branch 3 times, most recently from 51023a6 to 797153c Compare December 18, 2025 01:50
@tonyfettes tonyfettes force-pushed the haoxiang/refactor-server-to-use-httpx-router branch from 797153c to 856919e Compare December 29, 2025 07:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants