Standard library / net/http
http.NewRequest()
Construct an outgoing request; does not send it. Expected stdout: 'GET /a\n'.
Formal Syntax & Structure
go syntaxgo
func NewRequest(method, url string, body io.Reader) (*Request, error)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| method | string | HTTP method token. |
| url | string | Destination URL string. |
| body | io.Reader | Optional reader containing the request body. |
Return Value
(*Request, error)
Operation result; check errors and validity indicators when returned.
Working Example
Example Snippetgo
package main
import ( "fmt" "net/http")
func main() { r := must(http.NewRequest("GET", "https://example.invalid/a", nil)) fmt.Println(r.Method, r.URL.Path)}
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) }}