Skip to content

Simple Request Intercept to help understand an APIs structure

License

Notifications You must be signed in to change notification settings

StacklokLabs/reqparse

Folders and files

NameName
Last commit message
Last commit date

Latest commit

00d2844 · Nov 12, 2024

History

9 Commits
Nov 11, 2024
Nov 11, 2024
Nov 10, 2024
Nov 11, 2024
Nov 10, 2024
Nov 10, 2024
Nov 12, 2024
Nov 11, 2024
Nov 11, 2024

Repository files navigation

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

go install github.com/stackloklabs/reqparser@latest

Or clone and build manually:

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}
  1. With -pretty:
==================
JSON START
{
    "name": "test",
    "value": 123
}
==================
JSON END
==================
  1. With -headers:
Content-Type: application/json
User-Agent: curl/7.79.1
Accept: */*
Content-Length: 31

JSON-Body: {"name":"test","value":123}
  1. With -format go:
JSON-Body: {"name":"test","value":123}
Struct format:
type GeneratedStruct struct {
    name string `json:"name"`
    value float64 `json:"value"`
}
  1. 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)

About

Simple Request Intercept to help understand an APIs structure

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published