Created
August 9, 2020 23:16
-
-
Save ottino/d7367e24e7ee0a5e7c04dff934e65b21 to your computer and use it in GitHub Desktop.
js: funciones CRUD
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 characters
| 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 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment