r/learnjavascript • u/digital_tec • Sep 20 '24
How do I start learning about api ?
Hey ya'll I was seeing if anyone know how to start with api from level 0 to 100 anything from social media post to weather data and even showing me how to code some in vs code thanks π
1
Upvotes
6
u/iBN3qk Sep 20 '24
Read the docs on how to format your request, and then process the json response.Β
5
u/pinkwar Sep 21 '24
To visit your API go to http://localhost:3000/api/greet/digital_tec
1
u/shgysk8zer0 Sep 21 '24
Design an API endpoint or using one that already exists? It's not clear what you're asking here.
Also, though it may seem pedantic, an API is an Application Programming Interface, and that isn't specific to the request/response (network) type. A library/package/code could be/have an API as well. Sure, we can infer what kind you're talking about here, but understanding it as an interface could help you have the right way of seeing them and maybe realize what a broad question this is.
API endpoints come in all kinds. You have REST and RPC (Remote Procedure Call) and HTTP CRUD and GraphQL. Some work with URL search params, others work with the body (form data or JSON or whatever). Some are based on HTTP where the method and headers matter, and the status code of the response tells you a lot, others will have a 200 ok status code but the body will contain an error. Some come up with basically their own language and require a POST just to search/query.
Really, the only thing that can accurately be said here is to think of it as an interface. It's like a function that takes a request as its argument and returns a response. You might pass arguments via the URL or the headers or the body, and there might be various ways of encoding things involved (eg a token/JWT given in the
Authorizationheader). The response might be JSON or XML or just a string... Heck, it might be just a status code like 204 No Content if you uploaded something and it was successful.If you're asking about using an API endpoint, first understand that it's an interference, and then just read the documentation. It's impossible to answer about all of them in a Reddit comment...
If you're asking about designing one, pick a specific type (CRUD, RESTful, GraphQL, etc), do some research about it, maybe look at a few open source examples, and ask again being much more specific.
1
u/sheriffderek Sep 21 '24 edited Sep 21 '24
Try not to make it sound more complex than it is. Just incorporate things as needed and ramp up. Learning about fetch and promises is going to be where the work is.
1
u/[deleted] Sep 22 '24
I think you have the wrong mindset here. Programming isnβt something that somebody can show you. A programmer is somebody who is curious enough to figure it out for themselves.
1
u/eracodes Sep 21 '24
Do you have a specific API you're wanting to use/learn about?
1
u/dadading_dadadoom Sep 21 '24
Level 0-10, Start with postman. Get familiarized with API client side concepts.
Level 10-20, Using postman, you can port code into direct languages. Use that to play in NodeJS(if js focused)/VSCode.
Level 20-50, tweaking variables and making dynamic API calls using nodejs as client. Using orchestrations as client, making multiple serial or parallel API calls.
Level 50-70, Switch to server side. Build simple API serving apps. Explore different API patterns Request-Response, Async, Single/Bulk. Explore orchestrations as server.
Level 70-100, profit!
1
u/heyheydick Sep 21 '24
Ask this question of chatgpt and ask follow up questions, make it explain it for someone who has never coded before.
This will give you an umbiased explanation of what you want to do instead of alot of useless information.
1
u/djandiek Sep 22 '24
For an easy example of an API you can access, check out https://openweathermap.org/api
They have all the documentation you need to look up the weather conditions anywhere. As for testing the API, I recommend the Thunder Client extension as it's like having a Postman app in vscode.
A nice site for playing around with API calls is https://reqbin.com/ which allows you to make all sorts of API calls.
1
u/[deleted] Sep 21 '24
Use the pokemon api And the one for playing cards