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
-1
votes
1 answer

Angular 5 http.delete not sending Form data params

I have the following code: const requestData = { id: 123 }; this.http.delete(APIURL, {params: requestData}) .subscribe(() => { do_something }, () => { log_error }); For some reason, the .delete is not sending the…
Scobee
  • 448
  • 7
  • 22
-1
votes
1 answer

Angular multiple http.get requests

How can I make only one http request but subscribe multiple times to the service? The documentation states that they are called multiple times: const req = http.get('/api/heroes'); // 0 requests made - .subscribe() not…
Stefan
  • 14,826
  • 17
  • 80
  • 143
-1
votes
1 answer

Rest Spring Authentication call from UI: Pass username and password in request body, not in url parameter, to authenticate using spring security

I am using Spring security to do the authentication. From UI if I am posting the username and password in request body then I am geetin HTTP 401 error. But if I am posting username and password in URL then it working fine. Please find my Spring…
Suvonkar
  • 2,440
  • 12
  • 34
  • 44
-1
votes
1 answer

using HTTP client for Angular 5

I was following this here to learn how to work with the Http client. https://codecraft.tv/courses/angular/http/core-http-api/ In it, there is a reference to use URLSearchParams but - from what I have seen in another post URLSearchParams has been…
Casey Harrils
  • 2,793
  • 12
  • 52
  • 93
-1
votes
1 answer

Cannot use $http within angular factory (angular 1.x)

I have added $http at the start of the script but for some reason the $http isn't loaded - how do I log $http into the module rather than the controller var abcdReportServices = angular.module('abcdReportServices', […
Zabs
  • 13,852
  • 45
  • 173
  • 297
-1
votes
3 answers

Getting an Error while using Http module in Angular

I am using HttpModule to call my API. I have included the module in my imports and while starting my server an error is thrown(pl look at the screeshot). Error Image I am trying to call my API from the service using Http.post and getting the error…
user8885733
  • 137
  • 2
  • 13
-1
votes
2 answers

Use ".filter" in angular

I try filter data (get records with given number) http.get(baseUrl + 'api/Student/Students1') .filter( stud => stud.Phone == 123) .subscribe(data => { this.studentTEST = data.json() as Students[]; }, error => console.error(error)); But get…
St.S
  • 11
  • 5
-1
votes
2 answers

How to fetch data in Angular

can someone help me with getting number from http response in Angular 5 ? I don't now how to do it, I was searching at internet but Angular grow very fast so it doesn't help me. Thanks for any help ! My code: import { Injectable } from…
-1
votes
1 answer

why is the http service being called automatically

From the Http service the data is fetched and then is passed into cached service the compoenent subcribes to cached service and makes the http request when initiated. the http get service is supposed to be called when the user clicks on an anchor…
SONGSTER
  • 585
  • 3
  • 11
  • 28
-1
votes
1 answer

Can I post just JSON as data in Angular?

In angular 4, How can I post just JSON as data? Currently, my post code is: let options = { headers: new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded) }; let urlSearchParams = new…
Téwa
  • 1,184
  • 2
  • 13
  • 19
-1
votes
1 answer

Angular 4 restful API "PUT" and "POST" Methods

Anyone to help me in my new Angular 4 Project using HTTP request to GET, POST and PUT data using restful APIs. I managed to GET my data from the API but when I try to POST or PUT it always returns with OPTIONS…
-1
votes
1 answer

$http.put request changing into OPTIONS request in AngularJS 1.3.15

I'm new to the AngularJS. I'm using AngularJS 1.3.15 version. When I try to call an api with PUT method, It's generating OPTIONS request. I don't know where I'm doing mistake. I tried so many methods which is suggested in Stockoverflow, but still…
Manikandan S
  • 902
  • 1
  • 8
  • 18
-1
votes
1 answer

In Angular2/Typescript I want to load JSON data from a URL and bind to the Interface/Model

In Angular2/Typescript I want to load JSON data from a URL and bind to the Interface/Model. Sometime I want a single data object, other time I want to hold and array of the object. Which one(Interface/Model) should I use and why?
-1
votes
1 answer

Angular 2 services subscribed twice

I just start first project with Angular 2 and I've trouble with services. I've an http service called when submitting a form, but when I submit the form, the http request is executed twice. login.component.html
Maxime
  • 1,332
  • 1
  • 15
  • 43