Headers are useful for several reasons from design to security, but most often headers are used for metadata about the request or response itself. For example, let's say we wanted to ask for a specific project from the Jello server. We need to send that project's ID to the server so it knows which project to send back the information for. That ID is my request, it's not information about my request. However, we might include headers in that request to pass along extra information - like who is making the request.
Authentication is a common use case for headers. If I ask Jello to complete a project, I need to provide authentication information that I'm logged in, but that auth info isn't the request itself, it's just additional information about the request.
Because we don't want any of our users to accidentally overwrite another user's saved data, our backend team has required that we use the X-API-Key header for all requests to Jello's server. When we use different values, we're telling the server that we are a different person.
There's a bug in our code! It should:
Project object from the Jello API.Notice that the two objects that are logged to the console are the same. That's because the X-API-Key they are using is different, the update isn't being applied to the same account that we're checking in the last getProjectResponse call.