Check out a free preview of the full Full Stack for Front-End Engineers, v2 course:
The "Custom Header & Status Code Solution" Lesson is part of the full, Full Stack for Front-End Engineers, v2 course featured in this preview video. Here's what you'd learn in this lesson:

Jem shares the solution to the custom header and status code exercise.

Get Unlimited Access Now

Transcript from the "Custom Header & Status Code Solution" Lesson

>> Jem Young: So hopefully everybody was able to create a path, call it whatever you want. I chose demo, and instead of header and express we use res.set. And instead of status, we say res.status, so set any status you want. And send is just sending down some text data. You don't have to do that, but I thought it was pretty funny.

[00:00:22] Let's check this out. Just refresh the page, and there we go. I'm getting 418 as a status code. It says I'm a teapot because [LAUGH] yeah. And if we wanna look at the headers, we just go in there and we see this X full stacked for life. Just a custom header.

[00:00:41] So again, custom headers are a really powerful way of just sending down this one-time data for this request, because data are stateless. Requests are stateless. We could set a temporary state by sending a custom header. An example, another time when you set a header other than 200 would be a 401, not authorized.

[00:01:00] So you can check the cookie, check against a database of valid cookies or valid login credentials. And then if they're not logged in for every single request, you'd write some middleware that just returns a 401. Which means not authorised, which means hey, you're not logged in. The app can either return 401, which is just gonna error.

[00:01:18] Or you can handle it and say, hey, you need to log in if I get a 401 request. Any questions on headers, status codes, things like that before we move on? All right, everybody get this working?
>> Speaker 2: Is the X-header case-sensitive?
>> Jem Young: No, good question. It can be anything you want.

[00:01:37] Generally you can send down any header that you want as long as it's not one of the ones that are well-known. So like X-EPP-Content, X-EPP-Language, things like that. The X is just a standard for saying, this is a custom header. I don't expect you to do anything with it.

[00:01:52] I know what to do or just like some ancillary metadata that I'm attaching to this request. Hopefully everybody's able to get this working, if not, cool. All right.