0

I am working on a Unit Conversion API, and I am having a lot of issues with fetch(). My backend API is working, for example, when I call curl "http://localhost:8000/unitconv/convert?to=lb&from=kg&value=10" I get the correct response: {"units": "lb", "value": 22.04623}. Yet when I do the exact same thing with fetch(), this is what I get: Screenshot I have tried both localhost and 127.0.0.1 and I still cannot get past this "undefined". What's wrong here?

0

2 Answers 2

1

You are using a curly bracket in the first then without a return so nothing is going to the second then . It should be

.then((response) => {return response.json()}).then(() => ...
Sign up to request clarification or add additional context in comments.

1 Comment

Dang I can't believe it was something this dumb I should've noticed this, I'm too used to lisp right now and JS functional programming is something else dude.
1

You can simply omit the curly brackets like this:

fetch(url).then(response => response.json()).then(() =>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.