http
API reference for the http package, generated from Go doc comments.
import "github.com/grx-gql/grx/http"Package http provides the default GraphQL-over-HTTP+JSON transport.
It implements [core.Transport] for the canonical "POST a JSON body to /graphql" wire format described by the GraphQL over HTTP spec. Pair it with sse and websocket when subscriptions are needed.
The package name collides with the standard library's net/http; consumers that need both will alias one of the imports, e.g.
import (
"net/http"
grxhttp "github.com/grx-gql/grx/http"
)Index
type Config
Config tunes a Transport. All fields are optional; the zero value is a valid production configuration.
type Config struct{}type Transport
Transport implements [core.Transport] for GraphQL over HTTP+JSON. The zero value is ready to use; New exists for symmetry with the other built-in transports.
type Transport struct {
// contains filtered or unexported fields
}func New
func New(cfg ...Config) *TransportNew returns a Transport ready to be registered with the server. An optional Config may be supplied to override defaults.
func (Transport) Match
func (Transport) Match(r *nethttp.Request) boolMatch reports whether r is a POST request that this transport will handle. The server is responsible for filtering by URL path before dispatch, so the transport only validates the HTTP method here.
func (Transport) Serve
func (Transport) Serve(w nethttp.ResponseWriter, r *nethttp.Request, executor core.Executor)Serve decodes the JSON-encoded GraphQL request body, runs it through the executor, and writes the response as JSON. Request-level failures (invalid JSON, missing query) are surfaced as HTTP 400 with a GraphQL error envelope; field-level failures are surfaced as HTTP 200 with the errors array populated.
Generated by gomarkdoc
Last updated on