Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
G

gentleman

> 开发工具
Open source

Plugin-driven, extensible HTTP client toolkit for Go

1.1K stars0 likes1 views
WebsiteGitHub

About

Plugin-driven, extensible HTTP client toolkit for Go

gentleman

Full-featured, plugin-driven, middleware-oriented toolkit to easily create rich, versatile and composable HTTP clients in Go.

gentleman embraces extensibility and composition principles in order to provide a flexible way to easily create featured HTTP client layers based on built-in or third-party plugins that you can register and reuse across HTTP clients.

As an example, you can easily provide retry policy capabilities or dynamic server discovery in your HTTP clients simply attaching the retry or consul plugins.

Take a look to the examples, list of supported plugins, HTTP entities or middleware layer to get started.

For testing purposes, see baloo, an utility library for expressive end-to-end HTTP API testing, built on top of gentleman toolkit. For HTTP mocking, see gentleman-mock, which uses gock under the hood for easy and expressive HTTP client request mocking.

Versions

  • v2 - Latest version. Stable. Recommended.
  • v1 - First version. Stable. Actively maintained.

Features

  • Plugin driven architecture.
  • Simple, expressive, fluent API.
  • Idiomatic built on top of net/http package.
  • Context-aware hierarchical middleware layer supporting all the HTTP life cycle.
  • Built-in multiplexer for easy composition capabilities.
  • Easy to extend via plugins/middleware.
  • Ability to easily intercept and modify HTTP traffic on-the-fly.
  • Convenient helpers and abstractions over Go's HTTP primitives.
  • URL template path params.
  • Built-in JSON, XML and multipart bodies serialization and parsing.
  • Easy to test via HTTP mocking (e.g: gentleman-mock).
  • Supports data passing across plugins/middleware via its built-in context.
  • Fits good while building domain-specific HTTP API clients.
  • Easy to hack.
  • Dependency free.

Installation

bash
go get -u gopkg.in/h2non/gentleman.v2

Requirements

  • Go 1.9+

Plugins

Name
Docs
Status
Description




url

  
    
  


Easily declare URL, base URL and path values in HTTP requests




auth

  
    
  


Declare authorization headers in your requests




body

  
    
  


Easily define bodies based on JSON, XML, strings, buffers or streams




bodytype

  
    
  


Define body MIME type by alias




cookies

  
    
  


Declare and store HTTP cookies easily




compression

  
    
  


Helpers to define enable/disable HTTP compression




headers

  
    
  


Manage HTTP headers easily




multipart

  
    
  


Create multipart forms easily. Supports files and text fields




proxy

  
    
  


Configure HTTP proxy servers




query

  
    
  


Easily manage query params




redirect

  
    
  


Easily configure a custom redirect policy




timeout

  
    
  


Easily configure the HTTP timeouts (request, dial, TLS...)




transport

  
    
  


Define a custom HTTP transport easily




tls

  
    
  


Configure the TLS options used by the HTTP transport




retry

  
    
  


Provide retry policy capabilities to your HTTP clients




mock

  
    
  


Easy HTTP mocking using gock




consul

  
    
  


Consul based server discovery with configurable retry/backoff policy

Community plugins

Name
Docs
Status
Description




logger

  
    
  


Easily log requests and responses

Send a PR to add your plugin to the list.

Creating plugins

You can create your own plugins for a wide variety of purposes, such as server discovery, custom HTTP tranport, modify any request/response param, intercept traffic, authentication and so on.

Plugins are essentially a set of middleware function handlers for one or multiple HTTP life cycle phases exposing a concrete interface consumed by gentleman middleware layer.

For more details about plugins see the plugin package and examples.

Also you can take a look to a plugin implementation example.

HTTP entities

gentleman provides two HTTP high level entities: Client and Request.

Each of these entities provides a common API and are both middleware capable, giving you the ability to plug in custom components with own logic into any of them.

gentleman was designed to provide strong reusability capabilities. This is mostly achieved via its built-in hierarchical, inheritance-based middleware layer.

The following list describes how inheritance hierarchy works and is used across gentleman's entities.

  • Client entity can inherit from other Client entity.
  • Request entity can inherit from a Client entity.
  • Client entity is mostly designed for reusability.
  • Client entity can create multiple Request entities who implicitly inherits from Client entity itself.
  • Request entity is designed to have specific HTTP request logic that is not typically reused.
  • Both Client and Request entities are full middleware capable interfaces.
  • Both Client and Request entities can be cloned in order to produce a copy but side-effects free new entity.

You can see an inheritance usage example here.

Middleware

gentleman is completely based on a hierarchical middleware layer based on plugins that executes one or multiple function handlers (aka plugin interface) providing a simple way to plug in intermediate custom logic in your HTTP client.

It supports multiple phases which represents the full HTTP request/response life cycle, giving you the ability to perform actions before and after an HTTP transaction happen, even intercepting and stopping it.

The middleware stack chain is executed in FIFO order designed for single thread model. Plugins can support goroutines, but plugins implementors should prevent data race issues due to concurrency in multithreading programming.

For more implementation details about the middleware layer, see the middleware package and examples.

Middleware phases

Supported middleware phases triggered by gentleman HTTP dispatcher:

  • request - Executed before a request is sent over the network.
  • response - Executed when the client receives the response, even if it failed.
  • error - Executed in case that an error ocurrs, support both injected or native error.
  • stop - Executed in case that the request has been manually stopped via middleware (e.g: after interception).
  • intercept - Executed in case that the request has been intercepted before network dialing.
  • before dial - Executed before a request is sent over the network.
  • after dial - Executed after the request dialing was done and the response has been received.

Note that the middleware layer has been designed for easy extensibility, therefore new phases may be added in the future and/or the developer could be able to trigger custom middleware phases if needed.

Feel free to fill an issue to discuss this capabilities in detail.

API

See godoc reference for detailed API documentation.

Subpackages

  • plugin - godoc - Plugin layer for gentleman.
  • mux - godoc - HTTP client multiplexer with built-in matchers.
  • middleware - godoc - Middleware layer used by gentleman.
  • context - godoc - HTTP context implementation for gentleman's middleware.
  • utils - godoc - HTTP utilities internally used.

Examples

See examples directory for featured examples.

Simple request

…

Send JSON body

…

Composition via multiplexer

…

License

MIT - Tomas Aparicio

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Goclientconsulgolanghttp

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category开发工具
PricingOpen source

> Related tools

V
VS Code
流行的开源代码编辑器
G
Git
分布式版本控制系统
V
Vite
下一代前端构建工具