Which Http method to use?


#1

Hi All,

Which method for doing http calls should i use: The documenations isn’t clear what are the differences pros/cons of each method

Method 1 (as per interactive docs Lesson 2 Step 9)

using import { Http, Headers, Response } from "@angular/http";
and import { NativeScriptModule } from "nativescript-angular/nativescript.module";
in to the app.module
similar to how its done in normal angular

Method 2: (https://docs.nativescript.org/cookbook/http)

const httpModule = require("http");

and using methods such as httpModule.getString("https://httpbin.org/get") ...

Method 3 (https://docs.nativescript.org/tutorial/chapter-4)

var fetchModule = require("fetch");
and using methods such as fetchModule.fetch(config.apiUrl + "user/" + config.appKey + "/login", { method: "POST", body: JSON.stringify({ username: viewModel.get("email"), password: viewModel.get("password") }), headers: getCommonHeaders() })


#2

End of day, everything internally uses Http module only, it’s just more of different syntaxes. You may pick the one you like.

Of course if you are using Angular you must stick to HttpClientModule / axios or something if you use Vue. But down the line, internally everything uses the same http module.