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

Forkify API Error: Request timed out #386

Open
songhetian opened this issue Sep 14, 2023 · 9 comments
Open

Forkify API Error: Request timed out #386

songhetian opened this issue Sep 14, 2023 · 9 comments

Comments

@songhetian
Copy link

I've been learning with your course, and I find it amazing and all has been going smooth. Everything was fine before I went to bed last night, however, when I woke up this morning to continue with building the Forkify App, it keeps failing to generate data from the Forkify API. I visited the demo site (forkify-v2.netlify.app) and the same issue persisted. Please check kindly look into it.

@obiboss
Copy link

obiboss commented Jan 4, 2024

when i try to visit this site https://forkify-api.herokuapp.com/api/v2/recipes/ i receive an error message {
"status": "error",
"message": "Something went very wrong!"
} I would like to know how to resolve this

@akozdev
Copy link

akozdev commented Jan 4, 2024

The /recipes endpoint has a required search parameter, so in order to make it work, you will need to pass some search query, for example, /recipes?search=pizza.

I think the API should respond with a better message, and a different Http code in this case. We'll change it in the future.

@obiboss
Copy link

obiboss commented Jan 4, 2024

Thanks akozdev i noticed it worked on the browser but I didn't think to try it out in the code as it looked a bit weird

@obiboss
Copy link

obiboss commented Jan 4, 2024

However the goal was to sendJSON(url, recipe) but i get the error message so if i were to use this /recipes?search=pizza example i would get a list of pizza and not be able to send my own data

@obiboss
Copy link

obiboss commented Jan 4, 2024

The /recipes endpoint has a required search parameter, so in order to make it work, you will need to pass some search query, for example, /recipes?search=pizza.

I think the API should respond with a better message, and a different Http code in this case. We'll change it in the future.
Thanks for your response
However the goal was to sendJSON(url, recipe) but i get the error message so if i were to use this /recipes?search=pizza example i would get a list of pizza and not be able to send my own data

@akozdev
Copy link

akozdev commented Jan 4, 2024

To upload a new recipe, send a POST request to the /recipes endpoint. In this case, you only need to provide your API key in the params, like this /recipes?key=<your key> because POST requests are handled differently on this endpoint.

The sendJSON() function should already be configured to send POST requests

const fetchPromise = fetch(url, {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
      },
      body: JSON.stringify(uploadData),
    });

@obiboss
Copy link

obiboss commented Jan 4, 2024

To upload a new recipe, send a POST request to the /recipes endpoint. In this case, you only need to provide your API key in the params, like this /recipes?key=<your key> because POST requests are handled differently on this endpoint.

The sendJSON() function should already be configured to send POST requests

const fetchPromise = fetch(url, {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
      },
      body: JSON.stringify(uploadData),
    });

error
image
error
I am still getting error

helpers.js:33

   GET https://forkify-api.herokuapp.com/api/v2/recipes?key=924ac711-1d3b-4ccf-8271-2cae6c20e0fb 500 (Internal Server Error)

sendJSON @ helpers.js:33
await in sendJSON (async)
uploadRecipe @ model.js:140
controlAddRecipe @ controller.js:96
(anonymous) @ addRecipeView.js:40
controller.js:98 Error: Something went very wrong! 500
at sendJSON (helpers.js:35:24)
at async Object.uploadRecipe (model.js:140:18)
at async controlAddRecipe (controller.js:96:5)

@obiboss
Copy link

obiboss commented Jan 4, 2024

I have seen the error an unused variable i was using fetch(url) when i had created a variable named fetchPro to store it already. Thanks a lot it was really helpful

@akozdev
Copy link

akozdev commented Jan 4, 2024

You're welcome!

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

3 participants