go-forth
is a CLI-based HTTP client written in Go, designed for making various HTTP requests and displaying formatted responses. With support for multiple HTTP methods, styled JSON and HTML response formatting, and intuitive navigation, go-forth
provides a minimal yet powerful demonstration of CLI application development in Go.
- HTTP Method Selection: Easily switch between
GET
,POST
,PUT
,DELETE
, andPATCH
requests using a text input. - JSON and HTML Response Formatting: Automatically detects and pretty-prints JSON responses with syntax highlighting and indents HTML responses for readability.
- Error Handling: Provides clear error messages for invalid URLs, unsupported methods, non-200 HTTP status codes, and unsupported response formats.
- Enhanced CLI Interface: Uses
Bubble Tea
for interactive text and dropdown inputs, making the CLI experience smooth and intuitive. - Keyboard Navigation: Switch between inputs using
Tab
and arrow keys for seamless navigation.
- Install Go: Ensure you have Go installed. Go installation instructions
- Clone the Repository:
git clone https://github.com/wtwerner/go-forth.git cd go-forth
- Install Dependencies:
go get -u github.com/charmbracelet/lipgloss go get -u github.com/charmbracelet/bubbletea go get -u golang.org/x/net/html
Run the application from the command line:
go run main.go
- Enter a URL: Type the URL for the desired endpoint.
- Select an HTTP Method: Use
Tab
to switch to the method dropdown and choose fromGET
,POST
,PUT
,DELETE
, andPATCH
. - View Formatted Response: The application fetches the data and displays JSON responses with syntax highlighting or indented HTML responses for readability.
URL:
> http://api.github.com
HTTP method:
> GET
{
"current_user_url": "https://api.github.com/user",
"authorizations_url": "https://api.github.com/authorizations",
...
}
The project includes a comprehensive test suite covering:
- URL and HTTP Method Validation: Ensures URLs and methods are validated correctly.
- Error Handling: Simulates various error scenarios (e.g., invalid URL, unsupported method).
- JSON and HTML Formatting: Verifies that JSON and HTML responses are formatted properly.
To run the tests:
go test -v
Tests use httptest
to mock HTTP responses, allowing simulation of different server responses (e.g., JSON data, non-200 status codes, plain text).
main.go
: Contains the core CLI application logic, including HTTP requests, input handling, and response formatting.main_test.go
: Includes unit tests with mocked responses to ensure accurate application behavior.
- Bubble Tea - For building the interactive CLI interface
- Lip Gloss - For styling JSON and HTML responses in the terminal
- HTML Parser - For structured formatting of HTML responses
Feel free to contribute, report issues, or suggest improvements for go-forth
by opening an issue or pull request on GitHub.