MCPcopy Index your code
hub / github.com/aeilang/httpz

github.com/aeilang/httpz @v1.3.1

Chat with this repo
repository ↗ · DeepWiki ↗ · release v1.3.1 ↗ · + Follow
316 symbols 1,136 edges 46 files 116 documented · 37%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Logo

httpz v1.0.0 is release, its API is stable.

简体中文

httpz is not a new framework but rather an enhancement library for net/http. When you use httpz, you’re essentially working with the net/http standard library. Its goal is to address the usability gap in net/http 1.22, which, despite its improved routing capabilities, remains less convenient compared to frameworks like Echo and chi.

Key Features: - Built on net/http version 1.22+ - Global error handling - Convenient grouping - Middleware adopted from chi - Data binding adopted from Echo - Easy response shortcuts

httpz is fully compatible with net/http. You can choose to leverage the enhanced features of httpz or stick to using plain net/http directly.

Quick Start

1.Installation

To install httpz, Go 1.22 or higher is required.

go get github.com/aeilang/httpz

2.Hello World

import (
    "net/http"

    "github.com/aeilang/httpz"
    "github.com/aeilang/httpz/middleware"
)

func main() {
    // Create a new mux
    mux := httpz.NewServeMux()

    // add logger middleware, it 's copy from chi/middleware
    mux.Use(middleware.Logger)

    // register a GET /hello route
    // GET /hello
    mux.Get("/hello", func(w http.ResponseWriter, r *http.Request) error {
        // rw is a helper responsewriter to send response
        rw := httpz.NewHelperRW(w)
        return rw.String(http.StatusOK, "hello httpz")

        // or you can write it by yourself.
        // hw.Header().Set("Content-Type", "text/plain; charset=UTF-8")
        // hw.WriteHeader(http.StatusOK)
        // hw.Write([]byte("hello httpz"))
        // return nil
    })

  // just like net/http's ServerMux
    http.ListenAndServe(":8080", mux)
}

the middleware package is copied from chi/middleware.

The complete example can be found in the _example directory

Benchmark

Generated by Go web framework benchmark:

benchmark

For detailed benchmark results, please refer to benchmark.

Feel free to contribute your code.

  • test

  • example

  • middleware

  • other

Extension points exported contracts — how you extend this code

WrapResponseWriter (Interface)
WrapResponseWriter is a proxy around an http.ResponseWriter that allows you to hook into various parts of the response p [1 …
middleware/wrap_writer.go
LogFormatter (Interface)
LogFormatter initiates the beginning of a new LogEntry per request. See DefaultLogFormatter for an example implementatio [1 …
middleware/logger.go
HandlerFunc (FuncType)
HandlerFunc defines the function signature for a handler. It returns an error, which is used for centralized error handl
http.go
ErrHandlerFunc (FuncType)
ErrHandlerFunc defines the function signature for centralized error handling.
error.go
EncoderFunc (FuncType)
An EncoderFunc is a function that wraps the provided io.Writer with a streaming compression algorithm and returns it. I
middleware/compress.go
LogEntry (Interface)
LogEntry records the final log when a request completes. See defaultLogEntry for an example implementation. [1 implementers]
middleware/logger.go
MiddlewareFunc (FuncType)
MiddlewareFunc defines the function signature for middleware. It wraps an http.Handler and returns a new http.Handler.
http.go
LoggerInterface (Interface)
LoggerInterface accepts printing to stdlib logger or compatible logger.
middleware/logger.go

Core symbols most depended-on inside this repo

Get
called by 64
http.go
ServeHTTP
called by 60
http.go
NewHTTPError
called by 59
error.go
helper
called by 40
error.go
Write
called by 34
middleware/logger.go
NewServeMux
called by 28
http.go
cW
called by 28
middleware/terminal.go
Error
called by 26
error.go

Shape

Function 170
Method 89
Struct 37
TypeAlias 8
Interface 7
FuncType 5

Languages

Go100%

Modules by API surface

bind_test.go66 symbols
middleware/wrap_writer.go30 symbols
middleware/compress.go24 symbols
http.go20 symbols
middleware/logger.go17 symbols
helper_writer.go17 symbols
bind.go17 symbols
middleware/route_headers.go11 symbols
http_test.go9 symbols
error.go8 symbols
middleware/throttle.go7 symbols
middleware/recoverer.go7 symbols

For agents

$ claude mcp add httpz \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact