Package restful , a lean package for creating REST-style WebServices without magic. ### WebServices and Routes A WebService has a collection of Route objects that dispatch incoming Http Requests to a function calls. Typically, a WebService has a root path (e.g. /users) and defines common MIME types for its routes. WebServices must be added to a container (see below) in order to handler Http requests from a server. A Route is defined by a HTTP method, an URL path and (optionally) the MIME types it consumes (Content-Type) and produces (Accept). This package has the logic to find the best matching Route and if found, call its Function. The (*Request, *Response) arguments provide functions for reading information from the request and writing information back to the response. See the example https://github.com/emicklei/go-restful/blob/v3/examples/user-resource/restful-user-resource.go with a full implementation. ### Regular expression matching Routes A Route parameter can be specified using the format "uri/{var[:regexp]}" or the special version "uri/{var:*}" for matching the tail of the path. For example, /persons/{name:[A-Z][A-Z]} can be used to restrict values for the parameter "name" to only contain capital alphabetic characters. Regular expressions must use the standard Go syntax as described in the regexp package. (https://code.google.com/p/re2/wiki/Syntax) This feature requires the use of a CurlyRouter. ### Containers A Container holds a collection of WebServices, Filters and a http.ServeMux for multiplexing http requests. Using the statements "restful.Add(...) and restful.Filter(...)" will register WebServices and Filters to the Default Container. The Default container of go-restful uses the http.DefaultServeMux. You can create your own Container and create a new http.Server for that particular container. ### Filters A filter dynamically intercepts requests and responses to transform or use the information contained in the requests or responses. You can use filters to perform generic logging, measurement, authentication, redirect, set response headers etc. In the restful package there are three hooks into the request,response flow where filters can be added. Each filter must define a FilterFunction: Use the following statement to pass the request,response pair to the next filter or RouteFunction ### Container Filters These are processed before any registered WebService. ### WebService Filters These are processed before any Route of a WebService. ### Route Filters These are processed before calling the function associated with the Route. See the example https://github.com/emicklei/go-restful/blob/v3/examples/filters/restful-filters.go with full implementations. ### Response Encoding Two encodings are supported: gzip and deflate. To enable this for all responses: If a Http request includes the Accept-Encoding header then the response content will be compressed using the specified encoding. Alternatively, you can create a Filter that performs the encoding and install it per WebService or Route. See the example https://github.com/emicklei/go-restful/blob/v3/examples/encoding/restful-encoding-filter.go ### OPTIONS support By installing a pre-defined container filter, your Webservice(s) can respond to the OPTIONS Http request. ### CORS By installing the filter of a CrossOriginResourceSharing (CORS), your WebService(s) can handle CORS requests. ### Error Handling Unexpected things happen. If a request cannot be processed because of a failure, your service needs to tell via the response what happened and why. For this reason HTTP status codes exist and it is important to use the correct code in every exceptional situation. If path or query parameters are not valid (content or type) then use http.StatusBadRequest. Despite a valid URI, the resource requested may not be available If the application logic could not process the request (or write the response) then use http.StatusInternalServerError. The request has a valid URL but the method (GET,PUT,POST,...) is not allowed. The request does not have or has an unknown Accept Header set for this operation. The request does not have or has an unknown Content-Type Header set for this operation. ### ServiceError In addition to setting the correct (error) Http status code, you can choose to write a ServiceError message on the response. ### Performance options This package has several options that affect the performance of your service. It is important to understand them and how you can change it. DoNotRecover controls whether panics will be caught to return HTTP 500. If set to false, the container will recover from panics. Default value is true If content encoding is enabled then the default strategy for getting new gzip/zlib writers and readers is to use a sync.Pool. Because writers are expensive structures, performance is even more improved when using a preloaded cache. You can also inject your own implementation. ### Trouble shooting This package has the means to produce detail logging of the complete Http request matching process and filter invocation. Enabling this feature requires you to set an implementation of restful.StdLogger (e.g. log.Logger) instance such as: ### Logging The restful.SetLogger() method allows you to override the logger used by the package. By default restful uses the standard library `log` package and logs to stdout. Different logging packages are supported as long as they conform to `StdLogger` interface defined in the `log` sub-package, writing an adapter for your preferred package is simple. ### Resources (c) 2012-2025, http://ernestmicklei.com. MIT License
Package otlptracehttp provides an OTLP span exporter using HTTP with protobuf payloads. By default the telemetry is sent to https://localhost:4318/v1/traces. Exporter should be created using New. The environment variables described below can be used for configuration. OTEL_EXPORTER_OTLP_ENDPOINT (default: "https://localhost:4318") - target base URL ("/v1/traces" is appended) to which the exporter sends telemetry. The value must contain a scheme ("http" or "https") and host. The value may additionally contain a port and a path. The value should not contain a query string or fragment. The configuration can be overridden by OTEL_EXPORTER_OTLP_TRACES_ENDPOINT environment variable and by WithEndpoint, WithEndpointURL, WithInsecure options. OTEL_EXPORTER_OTLP_TRACES_ENDPOINT (default: "https://localhost:4318/v1/traces") - target URL to which the exporter sends telemetry. The value must contain a scheme ("http" or "https") and host. The value may additionally contain a port and a path. The value should not contain a query string or fragment. The configuration can be overridden by WithEndpoint, WithEndpointURL, WithInsecure, and WithURLPath options. OTEL_EXPORTER_OTLP_HEADERS, OTEL_EXPORTER_OTLP_TRACES_HEADERS (default: none) - key-value pairs used as headers associated with HTTP requests. The value is expected to be represented in a format matching the W3C Baggage HTTP Header Content Format, except that additional semi-colon delimited metadata is not supported. Example value: "key1=value1,key2=value2". OTEL_EXPORTER_OTLP_TRACES_HEADERS takes precedence over OTEL_EXPORTER_OTLP_HEADERS. The configuration can be overridden by WithHeaders option. OTEL_EXPORTER_OTLP_TIMEOUT, OTEL_EXPORTER_OTLP_TRACES_TIMEOUT (default: "10000") - maximum time in milliseconds the OTLP exporter waits for each batch export. OTEL_EXPORTER_OTLP_TRACES_TIMEOUT takes precedence over OTEL_EXPORTER_OTLP_TIMEOUT. The configuration can be overridden by WithTimeout option. OTEL_EXPORTER_OTLP_COMPRESSION, OTEL_EXPORTER_OTLP_TRACES_COMPRESSION (default: none) - the compression strategy the exporter uses to compress the HTTP body. Supported value: "gzip". OTEL_EXPORTER_OTLP_TRACES_COMPRESSION takes precedence over OTEL_EXPORTER_OTLP_COMPRESSION. The configuration can be overridden by WithCompression option. OTEL_EXPORTER_OTLP_CERTIFICATE, OTEL_EXPORTER_OTLP_TRACES_CERTIFICATE (default: none) - the filepath to the trusted certificate to use when verifying a server's TLS credentials. OTEL_EXPORTER_OTLP_TRACES_CERTIFICATE takes precedence over OTEL_EXPORTER_OTLP_CERTIFICATE. The configuration can be overridden by WithTLSClientConfig option. OTEL_EXPORTER_OTLP_CLIENT_CERTIFICATE, OTEL_EXPORTER_OTLP_TRACES_CLIENT_CERTIFICATE (default: none) - the filepath to the client certificate/chain trust for client's private key to use in mTLS communication in PEM format. OTEL_EXPORTER_OTLP_TRACES_CLIENT_CERTIFICATE takes precedence over OTEL_EXPORTER_OTLP_CLIENT_CERTIFICATE. The configuration can be overridden by WithTLSClientConfig option. OTEL_EXPORTER_OTLP_CLIENT_KEY, OTEL_EXPORTER_OTLP_TRACES_CLIENT_KEY (default: none) - the filepath to the client's private key to use in mTLS communication in PEM format. OTEL_EXPORTER_OTLP_TRACES_CLIENT_KEY takes precedence over OTEL_EXPORTER_OTLP_CLIENT_KEY. The configuration can be overridden by WithTLSClientConfig option.
Package receiver is a tiny HTTP target that records the request headers Cloud Tasks attaches when it dispatches (and re-dispatches) a task.
Package orange encodes and decodes HTTP range headers.
Package githubkit is a thin, composable HTTP kernel on top of google/go-github/v69: authentication, rate-limit budgeting fed from X-RateLimit-* response headers, retry with exponential backoff, typed sentinel errors, conditional ETag caching, and concurrent pagination.
Package fetchproxy implements the MQTT fetch-and-transform proxy described in issue #465: a device publishes a subscription naming an upstream URL, an optional set of HTTP headers, a poll interval, a destination MQTT topic, and a JavaScript transform that reduces the response body to the small object the device actually needs.
Package bingo binds HTTP request bodies, query parameters, path parameters, and headers into a single Go struct, then validates the completed request with one call.
Package ferryhttp loads configuration from an HTTP request into a Go struct: its query parameters, or its header fields.
Package hostdoctor is an SDK for checking the health of a host, server, URL or network service - HTTP, TLS, TCP, DNS, security headers and performance timing - condensed into one normalized report with a health score.
Package servertiming implements W3C Server-Timing header instrumentation for HTTP handlers.
Package observability wires OpenTelemetry into a Warren application: every handler gets a span and a duration histogram, every HTTP request continues the caller's trace, and trace context travels through a broker's message headers — by importing this module and listing it in warren.New.
Package alx parses, sorts and matches HTTP Accept-Language headers (RFC 9110 / RFC 4647).
Package header provides header value masking functionality for HTTP dumps.
Package fasthttp provides fast HTTP server and client API. Fasthttp provides the following features: Optimized for speed. Easily handles more than 100K qps and more than 1M concurrent keep-alive connections on modern hardware. Optimized for low memory usage. Easy 'Connection: Upgrade' support via RequestCtx.Hijack. Server provides the following anti-DoS limits: The number of concurrent connections. The number of concurrent connections per client IP. The number of requests per connection. Request read timeout. Response write timeout. Maximum request header size. Maximum request body size. Maximum request execution time. Maximum keep-alive connection lifetime. Early filtering out non-GET requests. A lot of additional useful info is exposed to request handler: Server and client address. Per-request logger. Unique request id. Request start time. Connection start time. Request sequence number for the current connection. Client supports automatic retry on idempotent requests' failure. Fasthttp API is designed with the ability to extend existing client and server implementations or to write custom client and server implementations from scratch.
Package dates is a lenient, dependency-free parser for the messy real-world date/time strings that appear on the wire: NNTP overview dates, RSS/Atom and JSONFeed pubDate values, RFC 5322 email Date headers, HTTP dates, and the like.
Package add_missing_headers provides a Traefik plugin for adding missing HTTP headers.
Package azcore implements an HTTP request/response middleware pipeline whose policy objects mutate an HTTP request's URL, query parameters, and/or headers before the request is sent over the wire.
Package grab provides a HTTP download manager implementation. Get is the most simple way to download a file: Get will download the given URL and save it to the given destination directory. The destination filename will be determined automatically by grab using Content-Disposition headers returned by the remote server, or by inspecting the requested URL path. An empty destination string or "." means the transfer will be stored in the current working directory. If a destination file already exists, grab will assume it is a complete or partially complete download of the requested file. If the remote server supports resuming interrupted downloads, grab will resume downloading from the end of the partial file. If the server does not support resumed downloads, the file will be retransferred in its entirety. If the file is already complete, grab will return successfully. For control over the HTTP client, destination path, auto-resume, checksum validation and other settings, create a Client: You can monitor the progress of downloads while they are transferring:
Package bunnypop provides HTTP middleware for verifying incoming requests against validity criteria derived from BunnyCDN PoP source checks or required headers.
Package cors provides an HTTP middleware that handles Cross-Origin Resource Sharing (CORS) by validating the Origin header and setting the appropriate Access-Control-* response headers.
Package cachecontrol provides Gin middleware for writing HTTP cache headers.
Package ja4 is a small, self-contained Caddy module that computes the base JA4 TLS client fingerprint (BSD-3-Clause algorithm, via github.com/exaring/ja4plus) at the edge and exposes it to HTTP handlers as {http.vars.ja4} and an upstream request header.
package illutls provides an HTTP client that simulates real browser TLS fingerprints and HTTP headers.
Package stampit surfaces Go VCS build info on every relevant surface: --version flags, HTTP headers, JSON endpoints, and startup logs.
Package requestid provides an HTTP middleware that extracts or generates a unique request ID for each request, propagates it through the request context, and echoes it back in the response header.
Package tracing provides an HTTP middleware that creates an OpenTelemetry server span for each request, extracts trace context from incoming headers, and records HTTP semantic attributes.
Package redisrouter is a Caddy HTTP handler that resolves a request's upstream (and optional per-route headers) by looking the request up in Redis.
Package redact strips sensitive data (auth headers, tokens, secrets, PII) from HTTP events before they're persisted.
Package idempo provides framework-agnostic HTTP middleware that makes unsafe requests idempotent using the IETF Idempotency-Key header.
Package proxy provides an HTTP middleware plugin for RoadRunner that resolves the real client IP address from proxy headers (Forwarded, X-Forwarded-For, X-Real-Ip, True-Client-Ip, Cf-Connecting-Ip) when requests arrive through trusted subnets.
Package headers provides an HTTP middleware plugin for RoadRunner that manages request and response HTTP headers.
Package propagation implements X-Cloud-Trace-Context header propagation used by Google Cloud products.