Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

321
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda