Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
A close look to Angular's new HttpClient
Search
Manfred Steyer
PRO
December 09, 2017
Programming
460
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
A close look to Angular's new HttpClient
Presentation from ng-be in December 2017.
Manfred Steyer
PRO
December 09, 2017
More Decks by Manfred Steyer
See All by Manfred Steyer
Generative UI & AI-Assistants for Your Angular Solutions
manfredsteyer
PRO
0
67
Nostalgia Meets Technology: Super Mario with TypeScript
manfredsteyer
PRO
0
120
Signal Forms: Details & Live Coding @enterJS 2026 in Mannheim
manfredsteyer
PRO
0
210
Strategic Design in the Frontend: Moduliths & Micro Frontends @DDDEurope
manfredsteyer
PRO
0
130
Agentic UI
manfredsteyer
PRO
0
210
Signal Forms: Beyond the Basics @ngBaguette 2026 in Paris
manfredsteyer
PRO
0
280
Agentic UI beyond Chats Architecture Patterns & Open Standards @ngMunich 05/2026
manfredsteyer
PRO
0
240
Agentic AI in the Frontend: Architectures with Open Standards @iJS London 2026
manfredsteyer
PRO
0
160
Agentic AI & UI: Arcitecture, HITL, Emerging Standards
manfredsteyer
PRO
0
190
Other Decks in Programming
See All in Programming
「AIで開発し、AIを届ける」をEvalでつなぐ 〜AIネイティブに始めるプロダクト開発の実践〜 / Connecting "Develop with AI, deliver AI" with Eval
rkaga
4
5.5k
The NotImplementedError Problem in Ruby
koic
1
990
Vite+ Unified Toolchain for the Web
naokihaba
0
380
ふつうのFeature Flag実践入門
irof
8
4.2k
Semantic Version 単位で戦略を柔軟に変えて、パッケージアップデートを自動化する
daitasu
1
320
Make SRE Operations Easier with Azure SRE Agent
kkamegawa
0
9.2k
Lessons from Spec-Driven Development
simas
PRO
0
230
気圧・高度・GPSを記録&可視化するアプリ「Koudo」を作った話
hjmkth
1
330
ECSアプリログをFireLensでコスト削減しようとしたけど諦めた話 in Fargate×Node.js
akihisaikeda
2
4.2k
Javaの型とAI時代に型が大事な理由 / java types and type in AI era
kishida
2
160
Dataformのリポジトリを立ち上げるときにまずやること / dataform-day0-2026
snhryt
0
200
LaravelLive Japan の裏方のすべて — 第188回 PHP勉強会@東京 (2026-06-24)
suguruooki
2
130
Featured
See All Featured
The browser strikes back
jonoalderson
0
1.3k
Java REST API Framework Comparison - PWX 2021
mraible
34
9.4k
Believing is Seeing
oripsolob
1
160
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
200
Darren the Foodie - Storyboard
khoart
PRO
3
3.4k
Code Reviewing Like a Champion
maltzj
528
40k
Faster Mobile Websites
deanohume
310
32k
Design of three-dimensional binary manipulators for pick-and-place task avoiding obstacles (IECON2024)
konakalab
0
480
Typedesign – Prime Four
hannesfritz
42
3.1k
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.3k
Claude Code どこまでも/ Claude Code Everywhere
nwiizo
65
56k
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.7k
Transcript
A close look to Angular's new HttpClient Manfred Steyer SOFTWAREarchitekt.at
About me … • Manfred Steyer • Angular Workshops and
Consultancy • SOFTWAREarchitekt.at • Google Developer Expert (GDE) Page ▪ 2 Manfred Steyer
In the old days, everything was better ;-)
Just a few examples …
Http in Angular Http (Service) • Angular 2+ • Most
Common Use Cases (80:20 principle) • Experimental • Deprecated with 5.0 HttpClient • Angular 4.3 • A lot of additional features • Full comfort we know from $http
Contents • Short overview of Basics • Custom Data Formats
(Binary, Text) • Progress Information • Interceptors for Extensions • Token-based Security
DEMO
angular-crud
None
Basics
HttpClient HttpClientModule and HttpClient from @angular/common/http let url = 'http://www.angular.at/api/hotel';
let headers = new HttpHeaders() .set('Accept', 'application/json'); let params = new HttpParams() .set('city', this.city); this .http .get<Hotel[]>(url, { headers, params }) .subscribe( hotels => console.debug('hotels', hotels), err => console.error('err', err) );
Getting the full HttpResponse save(entity: HotelBooking): Observable<string> { let url
= […] let headers = […] return this.http .post<HotelBooking>(url, entity, {headers, observe: 'response'}) […] }
Getting the full HttpResponse save(entity: HotelBooking): Observable<string> { let url
= […] let headers = […] return this.http .post<HotelBooking>(url, entity, {headers, observe: 'response'}) .pipe( map((response: HttpResponse<HotelBooking>) => { console.debug('status', response.status); console.debug('body', response.body); return response.headers.get('Location'); })); }
Testing
Main Idea: Mock the HttpBackend HttpClientTestingModule Your Code Test HttpClient
HttpBackend Server MockBackend
Testing it('can load hotels by city', () => { let
service: HotelService = TestBed.get(HotelService); let ctrl: HttpTestingController = TestBed.get(HttpTestingController); […] });
Testing it('can load hotels by city', () => { let
service: HotelService = TestBed.get(HotelService); let ctrl: HttpTestingController = TestBed.get(HttpTestingController); service.find({ city: 'Graz' }).subscribe( hotels => expect(hotels.length).toBe(2), err => fail(err) ); […] });
Testing it('can load hotels by city', () => { let
service: HotelService = TestBed.get(HotelService); let ctrl: HttpTestingController = TestBed.get(HttpTestingController); service.find({ city: 'Graz' }).subscribe( hotels => expect(hotels.length).toBe(2), err => fail(err) ); let req = ctrl.expectOne('/hotel?city=Graz'); expect(req.request.method).toBe('GET'); […] });
Testing it('can load hotels by city', () => { let
service: HotelService = TestBed.get(HotelService); let ctrl: HttpTestingController = TestBed.get(HttpTestingController); service.find({ city: 'Graz' }).subscribe( hotels => expect(hotels.length).toBe(2), err => fail(err) ); let req = ctrl.expectOne('/hotel?city=Graz'); expect(req.request.method).toBe('GET'); req.flush([{id: 1, name: 'Hotel Mama'}, {id: 2, name: 'Budget Hotel'}]); ctrl.verify(); });
Custom Data Formats (Text and Binary)
Using XML findById(id: string): Observable<HotelBooking> { […] return this.http .get(url,
{ headers, params, responseType: 'text'}) […] }
Using XML findById(id: string): Observable<HotelBooking> { […] return this.http .get(url,
{ headers, params, responseType: 'text'}) .pipe( switchMap(xmlString => { let observableFactory = bindCallback(parseString); return observableFactory(xmlString, parserOptions); }), map(js => js[1].hotelBooking) ); } import { parseString } from 'xml2js';
DEMO
Interceptors
Idea • Providing a hook • Modify requests and responses
globally • Including Headers, e. g. for Auth. • Parsing Data Formats, like XML • Error Handling • Caching • …
Chain of Responsibility Logic (HttpRequest) Interceptor Interceptor Request Response
DEMO Sending Access Token for Auth Global Error Handler for
Auth
Conclusion observe: response, events, … responseType: text, blob, … Interceptor
Chain The Dark Knight: Best Movie ever!
Contact und Downloads [mail]
[email protected]
[blog] SOFTWAREarchitekt.at [twitter] ManfredSteyer