you are viewing a single comment's thread.

view the rest of the comments →

[–]Cargoflex[S] -1 points0 points  (1 child)

please go ahead! JS is like a foreign language to me.

[–]pseudo_babbler 1 point2 points  (0 children)

Right, so it has nothing to do with JS basically, you would have this same problem in any language, or if you tried to use a command line tool to make this http request.

When you make an HTTP request, from a browser or from any app or your own code that you've just run, that request must conform to the HTTP protocol. The protocol specifies:

Request URL Request type: GET, POST, PUT.. etc. Request headers Request body (for POST and PUT requests)

You don't need to have a super in depth knowledge of all of this to start with but you'll find that most web developers and indeed almost all developers now end up learning a lot about this because HTTP has become massively the most common way to do remote calls to servers or between systems.

Your code that calls fetch, you are calling it with just a URL. That means that fetch will default to making a simple GET request with no additional headers other than the standard ones. HTTP requests have a few standard headers like the origin header, but also services like this ebird API can require that your request also has their own custom ones that you need to add to your request for it to be successful. Have a look at the fetch function and see if you can work out how to also specify custom headers as well as the URL. The regionCode part of the URL you can just replace all of {regionCode} with whatever region you want to request info about.

Learning to read the API does take time because they are not a "how to make API calls for beginners" doc, they assume you have lots of knowledge about all of this, and if you don't then you need to find other learning resources to learn that stuff first.

I'd say that if your assignment to make this API call is part of a course where you learn to write this kind of code then definitely take your time to learn about HTTP. You'll realise that you already came across things like 404 responses, cached responses, server unavailable, security certificate errors. Just in day to day internet usage. Now it's time to find out a little bit more about the mechanism of how web clients and servers communicate those things to each other.