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.
In this course, we have been and will continue to use the Fetch API to make HTTP requests. The fetch() method accepts an optional init object parameter as its second argument that we can use to define things like:
method: The HTTP method of the request, like GET.headers: The headers to send.mode: Used for security, we'll talk about this in future courses.body: The body of the request. Often encoded as JSON.Example GET request using fetch:
await fetch(url, {
method: "GET",
mode: "cors",
headers: {
"sec-ch-ua-platform": "macOS",
},
});
We need to write a reusable function that retrieves all of the Jello users from our server.
Complete the getUsers() function. It should:
We've done this all before, but now you're writing it all from scratch!