How does an Ionic application connect to a server?

-1

Creating a Mobile Client / Server Calculator

  • Create a calculator where the user enters two numbers and submits for a server to calculate
  • The server will do the calculation and your application will show the result for the user
  • The server is already implemented here: link
  • This server expects two values via GET (x and y) and returns the sum of them.

  • An example request would be: link

  • Soon, your task will be to create only the client side using Ionic

I already created the app in ionic, but how do I play the url of this server in my code? From what I understand, I have to import an HTTP API, and install a provider ... But how do you do that?

    
asked by anonymous 09.10.2018 / 20:52

1 answer

0

Friend, it's very simple. Just import the ionic library Native Http and make the requisitions to the necessary host. Ionic Documentation

Example:

import { HTTP } from '@ionic-native/http';

constructor(private http: HTTP) {}
this.http.get('http://enderecoservidor.io', {}, {})
  .then(data => {

    console.log(data.status);
    console.log(data.data); // data received by server
    console.log(data.headers);

  })
    
09.10.2018 / 22:37