19,99 €
In this book, I explain everything you need to know about connecting to backend Rest APIs from your Angular application. In this book, I will show you how to invoke different methods like GET, POST, and the like, how to use interceptors to inject an authentication token into every outgoing request, and much more. We will cover all areas of calling Rest APIs with Angular. By the end of this book, you will be able to call Rest APIs from your Angular application in any scenario. Let us get started.
Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:
Seitenzahl: 14
Veröffentlichungsjahr: 2024
Angular HTTP
Connecting to backend Rest APIs
Abdelfattah Ragab
In this book, I explain everything you need to know about connecting to backend Rest APIs from your Angular application.
In this book, I will show you how to invoke different methods like GET, POST, and the like, how to use interceptors to inject an authentication token into every outgoing request, and much more.
We will cover all areas of calling Rest APIs with Angular.
By the end of this book, you will be able to call Rest APIs from your Angular application in any scenario.
Let us get started.
Most front-end applications need to communicate with a server via the HTTP protocol to download or upload data and access other back-end services. Angular provides a client HTTP API for Angular applications, the HttpClient service class in @angular/common/http.
Before you can use the HttpClient in your application, you must configure it.
The HttpClient is provided with the help function provideHttpClient, which most applications include in the application providers in app.config.ts.
providers: [
provideHttpClient(),
]
};
provideHttpClient accepts a list of optional feature configurations, to enable or configure the behavior of different aspects of the client.
By default, the HttpClient uses the XMLHttpRequest API to make requests. The withFetch function switches the client to use the Fetch API instead.
fetch is a more modern API and is available in some environments where XMLHttpRequest is not supported. It has some limitations, e.g. no upload progress events are generated.
providers: [
provideHttpClient(
withFetch(),
),
]
};
You can then add the HttpClient service as a dependency of your components, services or other classes.