Questions tagged [angular-http]

AngularJS tag for $http service is a core Angular service that facilitates communication with the remote HTTP servers via the browser's XMLHttpRequest object or via JSONP.

The $http service is a core Angular service that facilitates communication with the remote HTTP servers via the browser's XMLHttpRequest object or via JSONP.

For unit testing applications that use $http service, see $httpBackend mock.

For a higher level of abstraction, please check out the $resource service.

The $http API is based on the deferred/promise APIs exposed by the $q service. While for simple usage patterns this doesn't matter much, for advanced usage it is important to familiarize yourself with these APIs and the guarantees they provide.

General usage

The $http service is a function which takes a single argument — a configuration object — that is used to generate an HTTP request and returns a promise with two $http specific methods: .then and .catch.

// Simple GET request example :
$http.get('/someUrl')
  .then(function(response) {
    var data = response.data;
    // this callback will be called asynchronously
    // when the response is available
}).catch(function(response) {
    // called asynchronously if an error occurs
    // or server returns response with an error status.
});
// Simple POST request example (passing data) :
$http.post('/someUrl', {msg:'hello word!'})
  .then(function(response) {
    // this callback will be called asynchronously
    // when the response is available
}).catch(function(response) {
    // called asynchronously if an error occurs
    // or server returns response with an error status.
});

Since the returned value of calling the $http function is a promise, you can also use the then method to register callbacks, and these callbacks will receive a single argument – an object representing the response. See the API signature and type info below for more details.

A response status code between 200 and 299 is considered a success status and will result in the success callback being called. Note that if the response is a redirect, XMLHttpRequest will transparently follow it, meaning that the error callback will not be called for such responses.

970 questions
4
votes
1 answer

AngularJS and Digest HTTP Authentication

I am trying to implement the digest auth algorithm in angular. However, the lack of knowledge about the requests angular will send stops me from perceiving that goal. My approach is to transform the request via the…
3
votes
3 answers

angular post request with content-type application/json not working

I try to send post request with angular but when i set content-type to application/json the request content-type always not set and the HTTP method always removed and all posted data removed from request body here my code and here my request
3
votes
1 answer

Angular URLSearchParams Vs HttpParams

Previously am using with import { Http, Response, Headers, URLSearchParams } from "@angular/http"; And for the API Call getprojectscount(city, param){ let urlSearchParams = new URLSearchParams(); urlSearchParams.set('limit', param.limit ); …
Abijith Ajayan
  • 238
  • 3
  • 17
3
votes
2 answers

Angular get body from HttpEvent<>

I'm performing a get request by calling this method of class AuthService: return this.http.post('url',{ "username": username, "password":password }, this.httpOptions).pipe(catchError(this.errorHandler)); from another…
Usr
  • 2,628
  • 10
  • 51
  • 91
3
votes
1 answer

Get Subscribe Data out of .subscribe in Angular

I want to return the events after the subscriber is called. getCalendarData(){ var body = JSON.stringify({"cid": "etNG3V61LWS6Pzkeb_omuZGMVAOLd1_70tRQblVizWQ~", "seldt":"2018-09-18"}); var headers = new HttpHeaders(); …
Nabid
  • 197
  • 5
  • 24
3
votes
0 answers

Angular: Set observe response

I know this is possible. return this.http.post(LoginUser, userData, {observe:'response'}).subscribe(data=>{ }) but doing this for all requests is cumbersome. I got the interceptor created. That is where I want to put observe response before making…
Nika Kurashvili
  • 6,006
  • 8
  • 57
  • 123
3
votes
2 answers

Angular Http Client sending to many request

Hi everybody I’m trying to put out a simple POST request via HttpClient from '@angular/common/http'; So i got my self a method which looks like this getRecommendations(answers: any, vehicles: Array) { // map answers to API interface const…
Jannik Lehmann
  • 468
  • 5
  • 25
3
votes
6 answers

Angular make multiple http request but wait for each one to finish before making a new one

In angular app I have an array of literal objects containing a url property. I need to make a http request for each of these object, but one after another. example: let arr = [ {url: 'http://example.com/url1'}, {url:…
dease
  • 2,975
  • 13
  • 39
  • 75
3
votes
0 answers

Angular-Interceptor: How to manage multiple loader/spinner on the page

We have an Angular6 application, where we have different components on the page, and each components has to display the loader when making API call. But this process is manual, each component has to maintain loading…
Tushar
  • 1,115
  • 1
  • 10
  • 26
3
votes
1 answer

Angular 6 httpclient error details

I have an Angular 6 app and when I make an http request: this.myService.login(this.form.email.value, this.form.password.value) .pipe(first()) .subscribe( data => { //do something on success …
user2818430
  • 5,853
  • 21
  • 82
  • 148
3
votes
1 answer

How to sort through HTTP GET Response to get one element at a time with Angular 5

This is my code for my DataService where I am mapping my Regions: import { Injectable, OnInit } from '@angular/core'; import { HttpClient, HttpParams } from "@angular/common/http" import { Observable } from 'rxjs/Observable'; import {…
3
votes
2 answers

Combine 3 streams with Observables in series and in parallel

I am trying to combine 3 HTTP requests into 1 response. The last 2 requests depend on data from the first request. I chose the following approach using flatMap and forkJoin after reading this post. The author is using an older version of Angular…
wper
  • 352
  • 2
  • 13
3
votes
4 answers

Angular5 Response Header (Content-Disposition) Reading

How Can I read Response Header (Content-Disposition)? Please share resolution. When I check at either Postman or Google Chrome Network tab, I can see 'Content-Disposition' at the response headers section for the HTTP call, but NOT able to read the…
Bhupal
  • 141
  • 1
  • 11
3
votes
3 answers

Sending two HTTP Requests one after each other using Angular / RXJS where second request requires the first?

Currently my code this by nesting observables inside each other... makeRequest() { return this.http.get().map((response: Response) => { return this.http.get(response.doSomething()); } } When I need to use it, I subscribe to them both using…
Winston Zhao
  • 79
  • 1
  • 8
3
votes
1 answer

angular-in-memory-web-api for query params other than object attributes

I have a collection of book objects in memory, book { title: string, author: string, description: string } Now the url for searching book is api/books/search/{text} the real web api does check for matches in all attributes of books including…