Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

319
Views
Javascript auth similar to Python auth?

I am trying to get data from a rest api call and with python request and it is working. How can I do similar in JavaScript and Typescript? I will need it in my Angular2 application.

Working Python script import requests

url = "restapi"

r = requests.post(url,  auth=('user', 'password'))
print(r.text)
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You need to use http (provided with RxJS)

Your import:

import { Http } from '@angular/http';

Injected in your constructor:

constructor(public http: Http) {}

Your rest request method:

login(user:User,onNext: (response) => void) {
    this.http
        .post(BASE_URL+"/login",user)
        .map(response => response.json())
        .subscribe(onNext,(e)=> console.error(`${e}`));
}

Note1: User is a typed json with just {user:string, password:string}

Note2: Please consider to do all the above in a @Injectable() Provider/Service, and the next step in your component (for beginning you can make everything in the same class)

Then use it like this

login(myUserJson,(result)=>{
     console.log(result);
     //proceed!...
})
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!