Created
August 9, 2020 23:16
-
-
Save ottino/d7367e24e7ee0a5e7c04dff934e65b21 to your computer and use it in GitHub Desktop.
Revisions
-
ottino created this gist
Aug 9, 2020 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,59 @@ const urlCRUD = 'https://reqres.in/api/users'; const getUsuario = async ( id )=> { const resp = await fetch(`${ urlCRUD }/${ id }`) ; const { data } = await resp.json(); return data; }; const crearUsuario = async ( usuario ) => { const resp = await fetch( urlCRUD , { method: 'POST', body: JSON.stringify( usuario ), headers: { 'Content-Type':'application/json' } }); return await resp.json(); } const actualizarUsuario = async ( id , usuario ) => { const resp = await fetch( `${ urlCRUD }/${ id }` , { method: 'PUT', body: JSON.stringify( usuario ), headers: { 'Content-Type':'application/json' } }); return await resp.json(); } const eliminarUsuario = async ( id ) => { const resp = await fetch(`${ urlCRUD }/${ id }` , { method:'DELETE' }); return ( resp.ok ) ? `id ${ id } eliminado` : 'No se pudo eliminar el usuario'; }; export { getUsuario, crearUsuario, actualizarUsuario, eliminarUsuario }