Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problema con la segunda url en **04-react-prueba-tecnica** #102

Open
francojimenezcopati opened this issue Jan 19, 2024 · 1 comment
Open

Comments

@francojimenezcopati
Copy link

Al entrar en la url de la segunda api, el json ya no tiene la url.

Ejemplo:
https://cataas.com/cat/says/hola?size=50&color=red&json=true

Devuelve:
{
"tags": [],
"createdAt": "2019-01-14T15:24:20.051Z",
"updatedAt": "2022-10-11T07:52:32.370Z",
"mimetype": "image/jpeg",
"size": null,
"id": "eaqTfY7LIJXCNhxZ"
}

@danyxriv
Copy link

danyxriv commented Apr 28, 2024

En mi caso lo resolví ocupando el id en un query params para formar un nuevo estado url y eso que forme parte en el src del img; de esa forma si no encuentra algún gato con la firtsWord almenos devolvera un gato aleatorio

Código:

const URL_API_CATS = `https://cataas.com/cat`

fetch(`${ URL_API_CATS }/says/${ firtsWord }?json=true`)
.then(res => res.json())
.then (resp => {
  console.log(resp)
  const { _id: id} = resp 
  setUrl(
    `${ URL_API_CATS }?id=${ id }&width=200`
  )
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants