https://github.com/stackloklabs/reqparse
Simple Request Intercept to help understand an APIs structure
https://github.com/stackloklabs/reqparse
Last synced: 3 months ago
JSON representation
Simple Request Intercept to help understand an APIs structure
- Host: GitHub
- URL: https://github.com/stackloklabs/reqparse
- Owner: StacklokLabs
- License: mit
- Created: 2024-11-11T12:54:28.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-11-11T13:04:44.000Z (about 1 year ago)
- Last Synced: 2024-11-11T13:39:10.085Z (about 1 year ago)
- Language: Go
- Homepage:
- Size: 0 Bytes
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ReqParser
ReqParser is a HTTP request parsing and formatting tool that accepts and logs HTTP requests, parses JSON data, and optionally converts it into Go or Rust struct definitions.
## Features
- Accepts and logs all HTTP methods (GET, POST, PUT, DELETE, etc.)
- Parses and displays JSON request bodies
- Optional conversion to programming language formats:
- Go structs
- Rust structs (with serde attributes)
- Pretty print JSON with delimiters
- Optional HTTP headers display
## Installation
```bash
go install github.com/stackloklabs/reqparser@latest
```
Or clone and build manually:
```bash
git clone https://github.com/stackloklabs/reqparser.git
cd reqparser
make build
```
### Flag Behavior
- With `-pretty`: Shows JSON with delimiters
- Without `-pretty`: Shows compact JSON-Body format
- With `-headers`: Shows HTTP headers
- With `-format go|rust` Generates a struct
* Note: Only parent structs, need to code up child struct generation
### Example Outputs
1. Basic usage (no flags):
```
JSON-Body: {"name":"test","value":123}
```
2. With `-pretty`:
```
==================
JSON START
{
"name": "test",
"value": 123
}
==================
JSON END
==================
```
3. With `-headers`:
```
Content-Type: application/json
User-Agent: curl/7.79.1
Accept: */*
Content-Length: 31
JSON-Body: {"name":"test","value":123}
```
4. With `-format go`:
```
JSON-Body: {"name":"test","value":123}
Struct format:
type GeneratedStruct struct {
name string `json:"name"`
value float64 `json:"value"`
}
```
5. With `-format rust`:
```
JSON-Body: {"name":"test","value":123}
Struct format:
#[derive(Debug, Serialize, Deserialize)]
struct GeneratedStruct {
#[serde(rename = "name")]
name: String,
#[serde(rename = "value")]
value: f64,
}
```
## Command Line Options
```
Usage of reqparser:
reqparser is a HTTP request parsing and formatting tool
Options:
-port int
Port to run the server on (default 8080)
-format string
Output format type (go, rust) - if not provided, no struct will be generated
-pretty
Pretty print JSON with delimiters (if not provided, shows compact JSON-Body)
-headers
Show HTTP headers in output
-version
Show version information
```
### Prerequisites
- Go 1.20 or later
- Make
- golangci-lint (installed automatically via Makefile)
- gosec (installed automatically via Makefile)