@ info: status
0:02
S… Speaker 1 (272. Setting Headers)
We now kind of enter the second part of this module,
0:06
S… Speaker 1 (272. Setting Headers)
you could say.
0:06
S… Speaker 1 (272. Setting Headers)
Thus far,
0:08
S… Speaker 1 (272. Setting Headers)
we had a thorough look at how we can send HTTP requests,
0:11
S… Speaker 1 (272. Setting Headers)
how we can handle errors,
0:12
S… Speaker 1 (272. Setting Headers)
how we can work with the data we get back if we don't have errors and
0:16
S… Speaker 1 (272. Setting Headers)
so on.
0:17
S… Speaker 2 (272. Setting Headers)
Now,
0:18
S… Speaker 1 (272. Setting Headers)
let me dive into a little bit more advanced parts of the Angular HTTP
0:22
S… Speaker 1 (272. Setting Headers)
client and how you can configure your requests and which kind of
0:26
S… Speaker 1 (272. Setting Headers)
different responses you can back and so on.
0:29
S… Speaker 1 (272. Setting Headers)
Let's start with headers.
0:31
S… Speaker 1 (272. Setting Headers)
When sending an HTTP request,
0:33
S… Speaker 1 (272. Setting Headers)
and of course we are configuring our requests in the post service,
0:37
S… Speaker 1 (272. Setting Headers)
so this is the place to look at now.
0:38
S… Speaker 1 (272. Setting Headers)
So when configuring these HTTP requests,
0:42
S… Speaker 1 (272. Setting Headers)
you set things like the URL you sent the request to,
0:45
S… Speaker 1 (272. Setting Headers)
or in the case of a post request,
0:47
S… Speaker 1 (272. Setting Headers)
you also set the data you wanna attach to your request.
0:51
S… Speaker 2 (272. Setting Headers)
Now,
0:53
S… Speaker 1 (272. Setting Headers)
of course,
0:53
S… Speaker 1 (272. Setting Headers)
sometimes you also need to set some special headers.
0:57
S… Speaker 1 (272. Setting Headers)
For example,
0:58
S… Speaker 1 (272. Setting Headers)
when you have a backend that requires authorization and looks for an authorization
1:03
S… Speaker 1 (272. Setting Headers)
header,
1:03
S… Speaker 1 (272. Setting Headers)
or if you wanna set your own content type,
1:07
S… Speaker 1 (272. Setting Headers)
or you need to attach a custom header because your API,
1:10
S… Speaker 1 (272. Setting Headers)
you're sending the request to needs it.
1:12
S… Speaker 2 (272. Setting Headers)
Now,
1:13
S… Speaker 1 (272. Setting Headers)
setting your own headers is extremely simple.
1:16
S… Speaker 1 (272. Setting Headers)
Any...
1:18
S… Speaker 1 (272. Setting Headers)
HTTP request method,
1:19
S… Speaker 1 (272. Setting Headers)
no matter if it's post or get or delete or patch or whatever,
1:23
S… Speaker 1 (272. Setting Headers)
any of these methods has an extra
1:27
S… Speaker 1 (272. Setting Headers)
last argument.
1:28
S… Speaker 1 (272. Setting Headers)
So in the case of get,
1:29
S… Speaker 1 (272. Setting Headers)
it's the second argument.
1:30
S… Speaker 1 (272. Setting Headers)
In the case of post,
1:31
S… Speaker 1 (272. Setting Headers)
it would be the third argument,
1:32
S… Speaker 1 (272. Setting Headers)
which is an object where you can configure that request.
1:35
S… Speaker 1 (272. Setting Headers)
And there you can configure a bunch of stuff,
1:38
S… Speaker 1 (272. Setting Headers)
as you can see,
1:39
S… Speaker 1 (272. Setting Headers)
and we'll start with the headers here.
1:41
S… Speaker 1 (272. Setting Headers)
And headers...
1:42
S… Speaker 1 (272. Setting Headers)
now takes a headers object,
1:44
S… Speaker 1 (272. Setting Headers)
which allows you to set the headers you want to send.
1:47
S… Speaker 1 (272. Setting Headers)
To be precise,
1:48
S… Speaker 1 (272. Setting Headers)
it's a HTTP headers object,
1:51
S… Speaker 1 (272. Setting Headers)
which you need to import from at Angular Common
1:55
S… Speaker 2 (272. Setting Headers)
HTTP.
1:55
S… Speaker 1 (272. Setting Headers)
So you need to add this import at the top.
1:58
S… Speaker 1 (272. Setting Headers)
And this allows you to create a new instance of
2:02
S… Speaker 1 (272. Setting Headers)
this object with a new keyword.
2:05
S… Speaker 1 (272. Setting Headers)
And to this object,
2:06
S… Speaker 1 (272. Setting Headers)
you can pass a JavaScript object here with the object literal notation,
2:10
S… Speaker 1 (272. Setting Headers)
where you can have key value pairs of your headers.
2:13
S… Speaker 1 (272. Setting Headers)
And headers are,
2:14
S… Speaker 1 (272. Setting Headers)
of course, key value pairs.
2:16
S… Speaker 1 (272. Setting Headers)
So for example,
2:18
S… Speaker 1 (272. Setting Headers)
here, you could set your custom header,
2:20
S… Speaker 1 (272. Setting Headers)
in case your API would need that,
2:22
S… Speaker 1 (272. Setting Headers)
to hello.
2:24
S… Speaker 1 (272. Setting Headers)
Or whatever you need.
2:25
S… Speaker 1 (272. Setting Headers)
You can set any header,
2:27
S… Speaker 1 (272. Setting Headers)
any HTTP header pair here.
2:29
S… Speaker 1 (272. Setting Headers)
If I do this and I save that,
2:32
S… Speaker 1 (272. Setting Headers)
and I now do try to fetch some posts.
2:34
S… Speaker 1 (272. Setting Headers)
I fetched posts as before,
2:37
S… Speaker 1 (272. Setting Headers)
but if we have a look at the network tab,
2:39
S… Speaker 1 (272. Setting Headers)
let's actually do that again with the cleared network tab,
2:42
S… Speaker 1 (272. Setting Headers)
and we have a look at our request here,
2:45
S… Speaker 1 (272. Setting Headers)
if we inspect the headers,
2:50
S… Speaker 1 (272. Setting Headers)
you see here on the request headers there is this custom header hello
2:54
S… Speaker 1 (272. Setting Headers)
and that's that custom header i attached and it's as simple as that you
2:58
S… Speaker 1 (272. Setting Headers)
can add as many headers as you want with this simple approach by
3:02
S… Speaker 1 (272. Setting Headers)
simply setting the headers config option here to a
3:06
S… Speaker 1 (272. Setting Headers)
new http headers object to which you pass your headers
3:11
S… Speaker 1 (272. Setting Headers)
in an object literal with a key value notation

@ info Politica IA

❤️ Amatz STT.ai? Ditz-lo als vòstres amics!
Resumit
@ action: button
Resumit...
Demandar a l'IA sus aquesta transcripcion
Demandatz quicòm sus aquesta transcripcion - l'IA trobarà las seccions pertinentas e respondrà.