PHP Classes

File: assets/js/components/lib/BuscaApiG.js

Recommend this page to a friend!
  Classes of Rodrigo Faustino   Web App Multi-Perfil   assets/js/components/lib/BuscaApiG.js   Download  
File: assets/js/components/lib/BuscaApiG.js
Role: Auxiliary data
Content type: text/plain
Description: Auxiliary data
Class: Web App Multi-Perfil
App that uses CRUD to manage multiple users
Author: By
Last change:
Date: 1 month ago
Size: 1,307 bytes
 

Contents

Class file image Download
export default class BuscaApi { constructor(token) { this.token = token; } async fetchApi(endpoint, method = 'GET', body = null) { const headers = { 'Authorization': this.token, 'Content-Type': 'application/json' }; const config = { method: method, headers: headers }; if (body) { config.body = JSON.stringify(body); } const response = await fetch(`backend/Router/${endpoint}`, config); return response.json(); } async fetchCEP(cep, method = 'GET') { const headers = { 'Content-Type': 'application/json' }; const config = { method: method, headers: headers }; const response = await fetch(`https://viacep.com.br/ws/${cep}/json/`, config); return response.json(); } async fetchGEO(geo, method = 'GET') { const headers = { 'Content-Type': 'application/json' }; const config = { method: method, headers: headers }; const response = await fetch(`https://nominatim.openstreetmap.org/search?q=${geo}&format=json&limit=1`, config); return response.json(); } }