Loading topic
HttpClient method (get, post, put, patch, delete, request) returns an RxJS Observable instead of a Promise. This choice affects how you write every data call in an Angular app. It decides when a request is sent, how it gets cancelled, how retries work, and what happens when t6 min readprovideHttpClient registers, which feature functions it accepts, and which setup mistakes cause most "No provider" errors and missing interceptors.4 min readHttpClient with provideHttpClient. This chapter is about where your code should use it. In Angular, the usual answer is a data service. A data service is an injectable class that owns all HTTP calls for one resource, such as todos, users or orders. Components ask 5 min readHttpClient with provideHttpClient and injected it into a TodoService, as the previous chapters showed. It also assumes you know basic RxJS: what subscribe does and how pipe chains operators.5 min readHttpClient registered with provideHttpClient, a TodoService that injects it, and a working typed get call. You should also be comfortable subscribing to an Observable and know what HTTP methods and status codes mean. Here we add the methods that change d7 min readHttpParams and HttpHeaders. Both are immutable, and that one design choice cau5 min readTodoService that injects HttpClient and returns typed Observables from get, post, put and delete, as built in earlier chapters. It also assumes you know how pipe works and that you are comfortable with HTTP status codes. Here you will learn what 6 min readasync pipe, toSignal, and a manual subscribe.4 min readHttpClient gives you only the parsed JSON body of a response. Usually that is all you need. Sometimes the body is not enough. A paginated API may put the total item count in a header. A file endpoint returns binary data, and a health check returns plain text. This chapter covers the tw5 min readTodoService method, it drifts out of sync and gets forgotten. An interceptor is a function that sits between 5 min readpipe, the TodoService from earlier chapters, and how toSignal turns an Observable into a signal. It covers two jobs that come up in almost every real screen. The first is stopping a request when its answer is no longer wanted. The second is coordinating sever5 min readHttpClient for progress events, turn them int5 min readdescribe, it, expect, spyOn), how TestBed configures providers, and how the TodoService and authInterceptor from earlier chapters work. The examples use Jasmine because it is Angular's long-standing default. With Jest5 min read