Standard library / net/http

http.Request

Represent an incoming or outgoing HTTP request, including method, URL, headers, body and context. Expected stdout: 'GET example.invalid\n'.

Formal Syntax & Structure

go syntaxgo
type Request struct {  Method string
  URL *url.URL
  Proto      string  ProtoMajor int  ProtoMinor int
  Header Header
  Body io.ReadCloser
  GetBody func() (io.ReadCloser, error)
  ContentLength int64
  TransferEncoding []string
  Close bool
  Host string
  Form url.Values
  PostForm url.Values
  MultipartForm *multipart.Form
  Trailer Header
  RemoteAddr string
  RequestURI string
  TLS *tls.ConnectionState
  Cancel <-chan struct{}
  Response *Response
  Pattern string
}

Working Example

Example Snippetgo
package main
import (  "fmt"  "net/http")
func main() {  r := must(http.NewRequest("GET", "https://example.invalid/", nil))  fmt.Println(r.Method, r.Host)}
func must[T any](v T, e error) T {  if e != nil {    panic(e)  }  return v}func check(e error) {  if e != nil {    panic(e)  }}
Go Reference