You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
//HEADERSservicioHttp("http://airemad.com/api/v1/").headers({'Accept': 'application/json','Content-Type': 'application/json'}).method("trace")//promesa o cb// comportamiento para GET, POST, PUT, DELETEservicioHttp("http://airemad.com/api/v1/").get("station/123").then(console.log).catch(console.warn)servicioHttp("http://airemad.com/api/v1/").get("station/123",(err,data)=>{if(err){console.warn(err)}else{console.log(data)}})// comportamiento para GET, POST, PUT, DELETEservicioHttp("http://airemad.com/api/v1/").post("station",{id:123}).then(console.log).catch(console.warn)
código
function$http(baseUrl){letheaders={}functionwrapperAjax({url, method, data}){constsetup={}setup.method=method;setup.headers=headers;if(data){setup.body=typeof(data)!=="string" ? JSON.stringify(data): data;}returnfetch(`${baseUrl+url}`,setup)}functionfallbackStrategy(prom,cb){if(cb&&typeof(cb)==="function"){prom.then(response=>response.json()).then(data=>cb(false,data)).catch(cb)}else{returnprom.then(response=>response.json())}}return{headers(obj){const_self=this;this.headers=obj;return_self;},method(verb,url,data,cb){returnfallbackStrategy(wrapperAjax({
url,method:verb, data
}),cb)},get(url,cb){returnfallbackStrategy(wrapperAjax({
url,method:"GET"}),cb)},post(url,data,cb){returnfallbackStrategy(wrapperAjax({
url,method:"POST", data
}),cb)},put(url,data,cb){returnfallbackStrategy(wrapperAjax({
url,method:"PUT", data
}),cb)},delete(url,cb){returnfallbackStrategy(wrapperAjax({
url,method:"DELETE"}),cb)}}}
Notas
Nivel 1
prueba
Librería
Nivel 2
prueba
código
Nivel 3 🦄
reto
código
Test Final
The text was updated successfully, but these errors were encountered: