SlideShare a Scribd company logo
HTTP AND OBSERVABLES IN
ANGULAR
BY: ABHISHEK PRASAD
210303130027(CC)
INTRODUCTION TO ANGULAR
What is Angular?
• A platform and framework for building single-page client applications using HTML
and TypeScript.
• Developed and maintained by Google, Angular integrates a range of features like
routing, forms management, and client-server communication.
CORE FEATURES OF ANGULAR:
• Component-Based Architecture: Angular structures applications as a tree of interconnected
components, each encapsulating elements of the UI.
• TypeScript-Based: Offers improved tooling, predictable static typing, and enhanced navigation and
refactoring services1.
• Data Binding: Facilitates the synchronization between the DOM and the component’s logic2.
• Dependency Injection: Angular’s powerful DI framework provides services to components, allowing for
greater modularity and reusability2.
• Directives: Extend HTML with new attributes called directives, which are great for encapsulating UI
behaviors2.
• Routing & Navigation: The Angular Router enables navigation from one view to the next as users
perform application tasks
UNDERSTANDING HTTP IN ANGULAR
HTTP in Web Applications
• HTTP (Hypertext Transfer Protocol) is the foundation of data
communication for the web, used for fetching HTML pages, files, or
data.
• In Angular, HTTP communication is handled through the HttpClient
module, which provides a way to perform HTTP requests and
handle responses.
UNDERSTANDING HTTP IN ANGULAR
Angular’s HttpClient
• A service that allows making HTTP requests to fetch or save data.
• Returns Observables to handle asynchronous operations, providing advantages like
cancellability and retry logic.
Making HTTP Requests
• Use HttpClient.get() to fetch data from a server.
• The method sends an HTTP request and returns an Observable that emits the requested data
when the response is received
UNDERSTANDING HTTP IN ANGULAR
Request Configuration
• Configure requests with headers, query parameters, and options for observing the
response or reporting progress.
• Important options include observe and responseType properties, which specify how much
of the response to return and the desired format of the returned data
Handling JSON Data
• Applications often request JSON data from servers.
• Angular’s HttpClient simplifies fetching JSON data, with most get() calls not requiring
additional options since JSON is the default data format
OBSERVABLES IN ANGULAR
What are Observables?
• A method for managing asynchronous data streams and events in Angular.
• They are part of the RxJS library and are used extensively within Angular
applications.
Key Features of Observables:
• Asynchronous Operations: Handle HTTP requests, user inputs, and events.
• Multiple Values Over Time: Emit zero or more values and handle them as a stream.
• Cancellation: Subscriptions to observables can be canceled, unlike promises.
• Operators: Apply functions to each item emitted by an observable.
OBSERVABLES IN ANGULAR
Usage in Angular
• HTTP Client: Angular’s HttpClient uses observables for handling AJAX requests and
responses.
• EventEmitter: Components communicate with each other using EventEmitter, which is an
observable that emits events.
• Async Pipe: Automatically subscribes to observables and updates the view with the latest
emitted values.
Advantages Over Promises
• More powerful and flexible, especially for complex data flows and multiple values.
• Better error handling and the ability to retry operations.
HTTP AND OBSERVABLES IN ANGULAR
Synergy of HTTP and Observables:
• Angular’s HttpClient uses Observables to handle HTTP requests, providing a robust framework for managing
asynchronous data.
Making HTTP Requests with Observables:
• Use HttpClient methods like get, post, put, and delete to interact with a server.
• These methods return Observables, allowing you to subscribe and handle the emitted data when the request is
completed.
Benefits of This Approach:
• Streamlined Error Handling: Use operators like catchError to manage errors gracefully.
• Cancellation: Cancel HTTP requests easily if they are no longer needed.
• Retry Logic: Implement retry strategies for failed HTTP requests using the retry operator.
FETCHING DATA WITH HTTP AND OBSERVABLES
Objective:
• Demonstrate how to fetch and display data from a server using Angular’s HttpClient and Observables.
Service Creation:
• Define a service that uses HttpClient to make a GET request.
• The service returns an Observable that emits the data when the response is received.
Component Subscription:
• In the component, subscribe to the Observable returned by the service.
• Assign the emitted data to a variable for display.
ERROR HANDLING IN HTTP REQUESTS
• Importance of Error Handling: Robust error handling is essential for a resilient Angular
application, ensuring a smooth user experience even when things go wrong.
• Using catchError Operator: The catchError operator is pivotal for handling errors in
Observable streams, particularly in HTTP requests made with Angular’s HttpClient.
• Centralizing Error Handling: Consider creating a global error-handling service that can be
used across different components and services for consistency and maintainability.
• Providing Meaningful Error Messages: When an error occurs, provide clear and actionable
feedback to the user, without exposing sensitive details.
• Logging Errors: Implement a logging strategy to capture errors for debugging and
monitoring application health.
THANK YOU

More Related Content

Similar to Http and observables in Angular .pptx

Single Page Applications in SharePoint with Angular
Single Page Applications in SharePoint with AngularSingle Page Applications in SharePoint with Angular
Single Page Applications in SharePoint with Angular
Sparkhound Inc.
 
Displaying google maps in mobileapplication.pptx
Displaying google maps in mobileapplication.pptxDisplaying google maps in mobileapplication.pptx
Displaying google maps in mobileapplication.pptx
sanaiftikhar23
 
A Real-Time collaboration Platform for Construction company
A Real-Time collaboration Platform for Construction companyA Real-Time collaboration Platform for Construction company
A Real-Time collaboration Platform for Construction company
Hemang Rindani
 
Angular js
Angular jsAngular js
Angular js
Janu Jahnavi
 
Angular js Online Training
Angular js Online TrainingAngular js Online Training
Angular js Online Training
Learntek1
 
Angular js
Angular jsAngular js
Angular js
Janu Jahnavi
 
OSGi compendium
OSGi compendiumOSGi compendium
OSGi compendium
Dario Bonino
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2
 
Angular crash course
Angular crash courseAngular crash course
Angular crash course
Birhan Nega
 
Angular js for Beginnners
Angular js for BeginnnersAngular js for Beginnners
Angular js for Beginnners
Santosh Kumar Kar
 
AngularJs (1.x) Presentation
AngularJs (1.x) PresentationAngularJs (1.x) Presentation
AngularJs (1.x) Presentation
Raghubir Singh
 
Angular js 1.3 basic tutorial
Angular js 1.3 basic tutorialAngular js 1.3 basic tutorial
Angular js 1.3 basic tutorial
Al-Mutaz Bellah Salahat
 
Single page application 02
Single page application   02Single page application   02
Single page application 02
Ismaeel Enjreny
 
Angular - Chapter 7 - HTTP Services
Angular - Chapter 7 - HTTP ServicesAngular - Chapter 7 - HTTP Services
Angular - Chapter 7 - HTTP Services
WebStackAcademy
 
Introduction to Angular JS
Introduction to Angular JSIntroduction to Angular JS
Introduction to Angular JS
Livares Technologies Pvt Ltd
 
Taking Akka Streams & Akka Http to Large Scale Production Applications
Taking Akka Streams & Akka Http to Large Scale Production ApplicationsTaking Akka Streams & Akka Http to Large Scale Production Applications
Taking Akka Streams & Akka Http to Large Scale Production Applications
Akara Sucharitakul
 
Mastering Angular: A Comprehensive Guide
Mastering Angular: A Comprehensive GuideMastering Angular: A Comprehensive Guide
Mastering Angular: A Comprehensive Guide
Jay Verma
 
Migrating from a monolith to microservices – is it worth it?
Migrating from a monolith to microservices – is it worth it?Migrating from a monolith to microservices – is it worth it?
Migrating from a monolith to microservices – is it worth it?
Katherine Golovinova
 
Angular presentation
Angular presentationAngular presentation
Angular presentation
merlihan
 
Building Aneka clouds.ppt
Building Aneka clouds.pptBuilding Aneka clouds.ppt
Building Aneka clouds.ppt
Dr. Vanajaroselin Chirchi
 

Similar to Http and observables in Angular .pptx (20)

Single Page Applications in SharePoint with Angular
Single Page Applications in SharePoint with AngularSingle Page Applications in SharePoint with Angular
Single Page Applications in SharePoint with Angular
 
Displaying google maps in mobileapplication.pptx
Displaying google maps in mobileapplication.pptxDisplaying google maps in mobileapplication.pptx
Displaying google maps in mobileapplication.pptx
 
A Real-Time collaboration Platform for Construction company
A Real-Time collaboration Platform for Construction companyA Real-Time collaboration Platform for Construction company
A Real-Time collaboration Platform for Construction company
 
Angular js
Angular jsAngular js
Angular js
 
Angular js Online Training
Angular js Online TrainingAngular js Online Training
Angular js Online Training
 
Angular js
Angular jsAngular js
Angular js
 
OSGi compendium
OSGi compendiumOSGi compendium
OSGi compendium
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
 
Angular crash course
Angular crash courseAngular crash course
Angular crash course
 
Angular js for Beginnners
Angular js for BeginnnersAngular js for Beginnners
Angular js for Beginnners
 
AngularJs (1.x) Presentation
AngularJs (1.x) PresentationAngularJs (1.x) Presentation
AngularJs (1.x) Presentation
 
Angular js 1.3 basic tutorial
Angular js 1.3 basic tutorialAngular js 1.3 basic tutorial
Angular js 1.3 basic tutorial
 
Single page application 02
Single page application   02Single page application   02
Single page application 02
 
Angular - Chapter 7 - HTTP Services
Angular - Chapter 7 - HTTP ServicesAngular - Chapter 7 - HTTP Services
Angular - Chapter 7 - HTTP Services
 
Introduction to Angular JS
Introduction to Angular JSIntroduction to Angular JS
Introduction to Angular JS
 
Taking Akka Streams & Akka Http to Large Scale Production Applications
Taking Akka Streams & Akka Http to Large Scale Production ApplicationsTaking Akka Streams & Akka Http to Large Scale Production Applications
Taking Akka Streams & Akka Http to Large Scale Production Applications
 
Mastering Angular: A Comprehensive Guide
Mastering Angular: A Comprehensive GuideMastering Angular: A Comprehensive Guide
Mastering Angular: A Comprehensive Guide
 
Migrating from a monolith to microservices – is it worth it?
Migrating from a monolith to microservices – is it worth it?Migrating from a monolith to microservices – is it worth it?
Migrating from a monolith to microservices – is it worth it?
 
Angular presentation
Angular presentationAngular presentation
Angular presentation
 
Building Aneka clouds.ppt
Building Aneka clouds.pptBuilding Aneka clouds.ppt
Building Aneka clouds.ppt
 

Recently uploaded

Recommendation System using RAG Architecture
Recommendation System using RAG ArchitectureRecommendation System using RAG Architecture
Recommendation System using RAG Architecture
fredae14
 
WeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation TechniquesWeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation Techniques
Postman
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
Zilliz
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
kumardaparthi1024
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
Zilliz
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
Hiroshi SHIBATA
 
Operating System Used by Users in day-to-day life.pptx
Operating System Used by Users in day-to-day life.pptxOperating System Used by Users in day-to-day life.pptx
Operating System Used by Users in day-to-day life.pptx
Pravash Chandra Das
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
akankshawande
 
UI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentationUI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentation
Wouter Lemaire
 
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
SitimaJohn
 
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
saastr
 
Trusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process MiningTrusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process Mining
LucaBarbaro3
 
System Design Case Study: Building a Scalable E-Commerce Platform - Hiike
System Design Case Study: Building a Scalable E-Commerce Platform - HiikeSystem Design Case Study: Building a Scalable E-Commerce Platform - Hiike
System Design Case Study: Building a Scalable E-Commerce Platform - Hiike
Hiike
 
Azure API Management to expose backend services securely
Azure API Management to expose backend services securelyAzure API Management to expose backend services securely
Azure API Management to expose backend services securely
Dinusha Kumarasiri
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
tolgahangng
 
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Jeffrey Haguewood
 
Deep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStr
Deep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStrDeep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStr
Deep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStr
saastr
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
Letter and Document Automation for Bonterra Impact Management (fka Social Sol...
Letter and Document Automation for Bonterra Impact Management (fka Social Sol...Letter and Document Automation for Bonterra Impact Management (fka Social Sol...
Letter and Document Automation for Bonterra Impact Management (fka Social Sol...
Jeffrey Haguewood
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
Brandon Minnick, MBA
 

Recently uploaded (20)

Recommendation System using RAG Architecture
Recommendation System using RAG ArchitectureRecommendation System using RAG Architecture
Recommendation System using RAG Architecture
 
WeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation TechniquesWeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation Techniques
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
 
Operating System Used by Users in day-to-day life.pptx
Operating System Used by Users in day-to-day life.pptxOperating System Used by Users in day-to-day life.pptx
Operating System Used by Users in day-to-day life.pptx
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
 
UI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentationUI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentation
 
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
 
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
 
Trusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process MiningTrusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process Mining
 
System Design Case Study: Building a Scalable E-Commerce Platform - Hiike
System Design Case Study: Building a Scalable E-Commerce Platform - HiikeSystem Design Case Study: Building a Scalable E-Commerce Platform - Hiike
System Design Case Study: Building a Scalable E-Commerce Platform - Hiike
 
Azure API Management to expose backend services securely
Azure API Management to expose backend services securelyAzure API Management to expose backend services securely
Azure API Management to expose backend services securely
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
 
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
 
Deep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStr
Deep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStrDeep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStr
Deep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStr
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
Letter and Document Automation for Bonterra Impact Management (fka Social Sol...
Letter and Document Automation for Bonterra Impact Management (fka Social Sol...Letter and Document Automation for Bonterra Impact Management (fka Social Sol...
Letter and Document Automation for Bonterra Impact Management (fka Social Sol...
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
 

Http and observables in Angular .pptx

  • 1. HTTP AND OBSERVABLES IN ANGULAR BY: ABHISHEK PRASAD 210303130027(CC)
  • 2. INTRODUCTION TO ANGULAR What is Angular? • A platform and framework for building single-page client applications using HTML and TypeScript. • Developed and maintained by Google, Angular integrates a range of features like routing, forms management, and client-server communication.
  • 3. CORE FEATURES OF ANGULAR: • Component-Based Architecture: Angular structures applications as a tree of interconnected components, each encapsulating elements of the UI. • TypeScript-Based: Offers improved tooling, predictable static typing, and enhanced navigation and refactoring services1. • Data Binding: Facilitates the synchronization between the DOM and the component’s logic2. • Dependency Injection: Angular’s powerful DI framework provides services to components, allowing for greater modularity and reusability2. • Directives: Extend HTML with new attributes called directives, which are great for encapsulating UI behaviors2. • Routing & Navigation: The Angular Router enables navigation from one view to the next as users perform application tasks
  • 4. UNDERSTANDING HTTP IN ANGULAR HTTP in Web Applications • HTTP (Hypertext Transfer Protocol) is the foundation of data communication for the web, used for fetching HTML pages, files, or data. • In Angular, HTTP communication is handled through the HttpClient module, which provides a way to perform HTTP requests and handle responses.
  • 5. UNDERSTANDING HTTP IN ANGULAR Angular’s HttpClient • A service that allows making HTTP requests to fetch or save data. • Returns Observables to handle asynchronous operations, providing advantages like cancellability and retry logic. Making HTTP Requests • Use HttpClient.get() to fetch data from a server. • The method sends an HTTP request and returns an Observable that emits the requested data when the response is received
  • 6. UNDERSTANDING HTTP IN ANGULAR Request Configuration • Configure requests with headers, query parameters, and options for observing the response or reporting progress. • Important options include observe and responseType properties, which specify how much of the response to return and the desired format of the returned data Handling JSON Data • Applications often request JSON data from servers. • Angular’s HttpClient simplifies fetching JSON data, with most get() calls not requiring additional options since JSON is the default data format
  • 7. OBSERVABLES IN ANGULAR What are Observables? • A method for managing asynchronous data streams and events in Angular. • They are part of the RxJS library and are used extensively within Angular applications. Key Features of Observables: • Asynchronous Operations: Handle HTTP requests, user inputs, and events. • Multiple Values Over Time: Emit zero or more values and handle them as a stream. • Cancellation: Subscriptions to observables can be canceled, unlike promises. • Operators: Apply functions to each item emitted by an observable.
  • 8. OBSERVABLES IN ANGULAR Usage in Angular • HTTP Client: Angular’s HttpClient uses observables for handling AJAX requests and responses. • EventEmitter: Components communicate with each other using EventEmitter, which is an observable that emits events. • Async Pipe: Automatically subscribes to observables and updates the view with the latest emitted values. Advantages Over Promises • More powerful and flexible, especially for complex data flows and multiple values. • Better error handling and the ability to retry operations.
  • 9. HTTP AND OBSERVABLES IN ANGULAR Synergy of HTTP and Observables: • Angular’s HttpClient uses Observables to handle HTTP requests, providing a robust framework for managing asynchronous data. Making HTTP Requests with Observables: • Use HttpClient methods like get, post, put, and delete to interact with a server. • These methods return Observables, allowing you to subscribe and handle the emitted data when the request is completed. Benefits of This Approach: • Streamlined Error Handling: Use operators like catchError to manage errors gracefully. • Cancellation: Cancel HTTP requests easily if they are no longer needed. • Retry Logic: Implement retry strategies for failed HTTP requests using the retry operator.
  • 10. FETCHING DATA WITH HTTP AND OBSERVABLES Objective: • Demonstrate how to fetch and display data from a server using Angular’s HttpClient and Observables. Service Creation: • Define a service that uses HttpClient to make a GET request. • The service returns an Observable that emits the data when the response is received. Component Subscription: • In the component, subscribe to the Observable returned by the service. • Assign the emitted data to a variable for display.
  • 11. ERROR HANDLING IN HTTP REQUESTS • Importance of Error Handling: Robust error handling is essential for a resilient Angular application, ensuring a smooth user experience even when things go wrong. • Using catchError Operator: The catchError operator is pivotal for handling errors in Observable streams, particularly in HTTP requests made with Angular’s HttpClient. • Centralizing Error Handling: Consider creating a global error-handling service that can be used across different components and services for consistency and maintainability. • Providing Meaningful Error Messages: When an error occurs, provide clear and actionable feedback to the user, without exposing sensitive details. • Logging Errors: Implement a logging strategy to capture errors for debugging and monitoring application health.