Created
June 11, 2020 02:47
-
-
Save parzibyte/0ef07e5555a0e87c9e01e93fbee06b21 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {Injectable} from '@angular/core'; | |
import {environment} from "../environments/environment"; | |
@Injectable({ | |
providedIn: 'root' | |
}) | |
export class HttpService { | |
rutaServidor = environment.baseUrl; | |
constructor() { | |
} | |
public async post(ruta: string, payload: any) { | |
const respuestaRaw = await fetch(this.rutaServidor + ruta, { | |
body: JSON.stringify(payload), | |
headers: { | |
"Content-Type": "application/json", | |
}, | |
method: "POST", | |
credentials: "include", | |
}); | |
return await respuestaRaw.json(); | |
} | |
public async formdata(ruta: string, payload: FormData) { | |
const respuestaRaw = await fetch(this.rutaServidor + ruta, { | |
body: payload, | |
method: "POST", | |
}); | |
return await respuestaRaw.json(); | |
} | |
async get(ruta: string) { | |
// Por defecto se hace una petición GET | |
const respuestaRaw = await fetch(this.rutaServidor + ruta, { | |
credentials: "include", | |
}); | |
return await respuestaRaw.json(); | |
} | |
async delete(ruta: string) { | |
const respuestaRaw = await fetch(this.rutaServidor + ruta, { | |
credentials: "include", | |
method: "DELETE", | |
}); | |
return await respuestaRaw.json(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment