logo
down
shadow

How to make http call and don't subscribe to response


How to make http call and don't subscribe to response

By : Aniket
Date : November 28 2020, 11:01 PM
I hope this helps you . Observables are lazy and don't do anything unless subscribe() is called.
You don't need to do anything though when data arrives
code :
this.http.get(url).subscribe()


Share : facebook icon twitter icon
Need to make an HTTP call to send email and get response

Need to make an HTTP call to send email and get response


By : Chetan Reddy
Date : March 29 2020, 07:55 AM
I wish this helpful for you Ruby's built in Net::HTTP library is plenty capable, but I like HTTPClient because it's got a nice set of simplified commands. The built-in open-uri is very convenient too if you don't need to do much heavy lifting.
For parsing HTML and XML, it's really hard to beat Nokogiri.
code :
require 'addressable/uri'
require 'nokogiri'
require 'open-uri'
url = 'https://sendgrid.com/api/mail.send.xml?api_user=youremail@domain.com&api_key=secureSecret&to=destination@example.com&toname=Destination&subject=Example%20Subject&text=testingtextbody&from=info@domain.com'
uri = Addressable::URI.parse(url)
uri.query_values # => {"api_user"=>"youremail@domain.com", "api_key"=>"secureSecret", "to"=>"destination@example.com", "toname"=>"Destination", "subject"=>"Example Subject", "text"=>"testingtextbody", "from"=>"info@domain.com"}
doc = Nokogiri::XML(open(uri.to_s))
returned_xml = '<result>
  <message>success</message>
</result>'
doc = Nokogiri::XML(returned_xml)
doc.at('message').inner_text # => "success"
How to make HTTP POST call in Angular2 and print the response

How to make HTTP POST call in Angular2 and print the response


By : Jose Carlos Barba Gu
Date : March 29 2020, 07:55 AM
should help you out I am new to Angular2 and buuilding a sample project to learn it. I am curently looking at how to make HTTP calls in Angular2 and found this code snippet example: ,
My question is how would I print the response to the console?
code :
.subscribe((res:Person) => { this.postResponse = res; console.log(res); });
.map((res: Response) => res.json())
.subscribe(
     (response) => {
            /* this function is executed every time there's a new output */
           console.log("VALUE RECEIVED: "+response);
     },
     (err) => {
            /* this function is executed when there's an ERROR */
            console.log("ERROR: "+err);
     },
     () => {
            /* this function is executed when the observable ends (completes) its stream */
            console.log("COMPLETED");
     }
 );
Angular 2: How to call a function after get a response from subscribe http.post

Angular 2: How to call a function after get a response from subscribe http.post


By : Ever Dev
Date : March 29 2020, 07:55 AM
should help you out Update your get_categories() method to return the total (wrapped in an observable):
code :
// Note that .subscribe() is gone and I've added a return.
get_categories(number) {
  return this.http.post( url, body, {headers: headers, withCredentials:true})
    .map(response => response.json());
}
// send_categories() is now called after get_categories().
search_categories() {
  this.get_categories(1)
    // The .subscribe() method accepts 3 callbacks
    .subscribe(
      // The 1st callback handles the data emitted by the observable.
      // In your case, it's the JSON data extracted from the response.
      // That's where you'll find your total property.
      (jsonData) => {
        this.send_categories(jsonData.total);
      },
      // The 2nd callback handles errors.
      (err) => console.error(err),
      // The 3rd callback handles the "complete" event.
      () => console.log("observable complete")
    );
}
obs.subscribe(
  nextCallback,
  errorCallback,
  completeCallback
);
obs.subscribe(nextCallback);
How to loop through a http response with another request, extending the initial response, before subscribe?

How to loop through a http response with another request, extending the initial response, before subscribe?


By : user3326311
Date : March 29 2020, 07:55 AM
like below fixes the issue At first change your rxjs map to switchMap, then you can iterate through data from first Observable, and create an array of observables which can be returned as forkJoin in switchMap.
Code:
code :
switchMap(res => {
  const requests = res.map(contact => {
    return this.http.get<any>('getUserById?userId=' + contact.userId);
  });

  return forkJoin(requests);
}, (resData, usersData) => [resData, usersData]),
map(([res, usersRes]) => {
  return res.map(contact => {
    const foundUser = usersRes.find(user => user.id === res.id);

    return {
      ...res,
      ...foundUser
    };
  });
})
switchMap(res => {
  const requests = res.map(contact => {
    return this.http.get<any>('getUserById?userId=' + contact.userId).pipe(
      map(userData => {
        return { ...contact, ...userData };
      })
    );
  });

  return forkJoin(requests);
})
function with get / http / subscribe dont worked, why?

function with get / http / subscribe dont worked, why?


By : user3619097
Date : March 29 2020, 07:55 AM
Hope that helps This function with get / http / subscribe does not return the correct value, it returns undefined, why?` , without seeing the rest of the code: I would recommend this:
code :
getData() {
  //return observable
  return this.http.get("assets/img/tutorial/tutorialenus.JSON");
}

function_one() {
  //subscribe to and log observable response data
  this.getData().subscribe
  (response => {
    console.log(' Here response = The simple text', response);
  }
}
shadow
Privacy Policy - Terms - Contact Us © soohba.com