I need more understanding to api and local servers

I’m new to using APIs, i have learned to build a localhost server and route post and get. Then i watched a tutorial on YouTube where the author didn’t build a local server but just used the api in js file and it worked so it made me confused about the usage of servers with api!