

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Still calibrating
click for more info
Not enough gems
Cost: 6 gems
1: HTTP Methods - GET
incomplete
2: Why Use HTTP Methods?
incomplete
3: POST Requests
incomplete
4: Status Codes
incomplete
5: Status Code Property
incomplete
6: HTTP PUT
incomplete
7: Patch vs. PUT
incomplete
8: Delete
incomplete
This lesson's interactive features are locked, please to keep using them
HTTP defines a set of methods. We must choose one to use each time we make an HTTP request. The most common ones include:
GETPOSTPUTDELETEThe GET method is used to "get" a representation of a specified resource. It doesn't take (remove) the data from the server but rather gets a representation, or copy, of the resource in its current state. A GET request is considered a safe method to call multiple times because it shouldn't alter the state of the server.
There are two basic ways to make a Get request in Go.
http.Gethttp.Client, http.NewRequest, and http.Client.DoIf all you need to do is make a simple GET request to a URL, http.Get will work:
resp, err := http.Get("https://jsonplaceholder.typicode.com/users")
If you need to customize things like headers, cookies, or timeouts, you'll want to create a custom http.Client, and http.NewRequest, then use the client's Do method to execute it.
client := &http.Client{
Timeout: time.Second * 10,
}
req, err := http.NewRequest("GET", "https://jsonplaceholder.typicode.com/users", nil)
if err != nil {
log.Fatal(err)
}
resp, err := client.Do(req)
Complete the getUsers function. It should:
We've done this all before, but now you're writing it all from scratch!