An HTTP request value stores the method, URL, host, and path before any network call is made.

request object A client prepares a method, host, and path before any network call is made.

Build Request

endpoint
build_request.go
Replay: real traced execution (multi-file project)
package main

import "fmt"

func splitEndpoint(endpoint string) (string, string) {
	rest := endpoint[len("https://"):]
	slashIndex := 0
	for index, letter := range rest {
		if letter == '/' {
			slashIndex = index
			break
		}
	}
	host := rest[:slashIndex]
	path := rest[slashIndex:]
	return host, path
}

func main() {
	var endpoint = "https://api.example.test/users"
	host, path := splitEndpoint(endpoint)

	method := "GET"
	fmt.Println("method=", method)
	fmt.Println("host=", host)
	fmt.Println("path=", path)
}
package main

import "fmt"

func splitEndpoint(endpoint string) (string, string) {
	rest := endpoint[len("https://"):]
	slashIndex := 0
	for index, letter := range rest {
		if letter == '/' {
			slashIndex = index
			break
		}
	}
	host := rest[:slashIndex]
	path := rest[slashIndex:]
	return host, path
}

func main() {
	var endpoint = "https://api.example.test/projects"
	host, path := splitEndpoint(endpoint)

	method := "GET"
	fmt.Println("method=", method)
	fmt.Println("host=", host)
	fmt.Println("path=", path)
}
package main

import "fmt"

func splitEndpoint(endpoint string) (string, string) {
	rest := endpoint[len("https://"):]
	slashIndex := 0
	for index, letter := range rest {
		if letter == '/' {
			slashIndex = index
			break
		}
	}
	host := rest[:slashIndex]
	path := rest[slashIndex:]
	return host, path
}

func main() {
	var endpoint = "https://docs.example.test/search"
	host, path := splitEndpoint(endpoint)

	method := "GET"
	fmt.Println("method=", method)
	fmt.Println("host=", host)
	fmt.Println("path=", path)
}
  1. endpoint ← "https://api.example.test/users"

    19func main() {20  var endpoint→ "https://api.example.test/users" = "https://api.example.test/users" //@endpoint="https://api.example.test/projects", "https://docs.example.test/search"21  host, path := splitEndpoint(endpoint"https://api.example.test/users")
  2. rest ← "api.example.test/users", slashIndex ← 0

    5func splitEndpoint(endpoint"https://api.example.test/users" string) (string, string) {6  rest→ "api.example.test/users" := endpoint"https://api.example.test/users"[len("https://"):]7  slashIndex→ 0 := 08  for index, letter := range rest {
  3. for index, letter := range rest

    pass 1 of 17
    7slashIndex := 08for index0, letter97 := range rest"api.example.test/users" {9  if letter == '/' {
    17 passes — pass 1 is the card above
    passindexletterslashIndex
    1097
    21112
    32105
    4346
    54101
    65120
    7697
    87109
    98112
    ⋯ 6 more passes ⋯
    1615116
    1716470 16
  4. slashIndex ← 16

    8for index, letter := range rest {9  if letter47 == '/' {10    slashIndex→ 16 = index1611    break12  }
  5. host ← "api.example.test"

    13  }14  host→ "api.example.test" := rest"api.example.test/users"[:slashIndex16]15  path := rest"api.example.test/users"[slashIndex16:]16  return host"api.example.test", path17}
  6. host ← "api.example.test", method ← "GET"

    20  var endpoint = "https://api.example.test/users" //@endpoint="https://api.example.test/projects", "https://docs.example.test/search"21  host→ "api.example.test", path := splitEndpoint(endpoint"https://api.example.test/users")2223  method→ "GET" := "GET"24  fmt.Println("method=", method"GET")25  fmt.Println("host=", host"api.example.test")26  fmt.Println("path=", path)27}
    outputmethod= GET
    host= api.example.test
    path= /users
  1. endpoint ← "https://api.example.test/projects"

    19func main() {20  var endpoint→ "https://api.example.test/projects" = "https://api.example.test/projects"21  host, path := splitEndpoint(endpoint"https://api.example.test/projects")
  2. rest ← "api.example.test/projects", slashIndex ← 0

    5func splitEndpoint(endpoint"https://api.example.test/projects" string) (string, string) {6  rest→ "api.example.test/projects" := endpoint"https://api.example.test/projects"[len("https://"):]7  slashIndex→ 0 := 08  for index, letter := range rest {
  3. for index, letter := range rest

    pass 1 of 17
    7slashIndex := 08for index0, letter97 := range rest"api.example.test/projects" {9  if letter == '/' {
    17 passes — pass 1 is the card above
    passindexletterslashIndex
    1097
    21112
    32105
    4346
    54101
    65120
    7697
    87109
    98112
    ⋯ 6 more passes ⋯
    1615116
    1716470 16
  4. slashIndex ← 16

    8for index, letter := range rest {9  if letter47 == '/' {10    slashIndex→ 16 = index1611    break12  }
  5. host ← "api.example.test"

    13  }14  host→ "api.example.test" := rest"api.example.test/projects"[:slashIndex16]15  path := rest"api.example.test/projects"[slashIndex16:]16  return host"api.example.test", path17}
  6. host ← "api.example.test", method ← "GET"

    20  var endpoint = "https://api.example.test/projects"21  host→ "api.example.test", path := splitEndpoint(endpoint"https://api.example.test/projects")2223  method→ "GET" := "GET"24  fmt.Println("method=", method"GET")25  fmt.Println("host=", host"api.example.test")26  fmt.Println("path=", path)27}
    outputmethod= GET
    host= api.example.test
    path= /projects
  1. endpoint ← "https://docs.example.test/search"

    19func main() {20  var endpoint→ "https://docs.example.test/search" = "https://docs.example.test/search"21  host, path := splitEndpoint(endpoint"https://docs.example.test/search")
  2. rest ← "docs.example.test/search", slashIndex ← 0

    5func splitEndpoint(endpoint"https://docs.example.test/search" string) (string, string) {6  rest→ "docs.example.test/search" := endpoint"https://docs.example.test/search"[len("https://"):]7  slashIndex→ 0 := 08  for index, letter := range rest {
  3. for index, letter := range rest

    pass 1 of 18
    7slashIndex := 08for index0, letter100 := range rest"docs.example.test/search" {9  if letter == '/' {
    18 passes — pass 1 is the card above
    passindexletterslashIndex
    10100
    21111
    3299
    43115
    5446
    65101
    76120
    8797
    98109
    ⋯ 7 more passes ⋯
    1716116
    1817470 17
  4. slashIndex ← 17

    8for index, letter := range rest {9  if letter47 == '/' {10    slashIndex→ 17 = index1711    break12  }
  5. host ← "docs.example.test"

    13  }14  host→ "docs.example.test" := rest"docs.example.test/search"[:slashIndex17]15  path := rest"docs.example.test/search"[slashIndex17:]16  return host"docs.example.test", path17}
  6. host ← "docs.example.test", method ← "GET"

    20  var endpoint = "https://docs.example.test/search"21  host→ "docs.example.test", path := splitEndpoint(endpoint"https://docs.example.test/search")2223  method→ "GET" := "GET"24  fmt.Println("method=", method"GET")25  fmt.Println("host=", host"docs.example.test")26  fmt.Println("path=", path)27}
    outputmethod= GET
    host= docs.example.test
    path= /search