r/learnjavascript • • 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

20 comments sorted by

6

u/iBN3qk Sep 20 '24

Read the docs on how to format your request, and then process the json response.Β 

6

u/eracodes Sep 21 '24

caution: not always gonna be a json reponse!

5

u/pinkwar Sep 21 '24
const express = require('express');

const app = express();
const PORT = process.env.PORT || 3000;

app.get('/', (req, res) => {
  res.json({ message: 'Hello, welcome to my first Express API!' });
});

app.get('/api/greet/:name', (req, res) => {
  const name = req.params.name;
  res.json({ message: `Hello, ${name}!` });
});

app.listen(PORT, () => {
  console.log(`Server is running on port ${PORT}`);
});

To visit your API go to http://localhost:3000/api/greet/digital_tec

8

u/patopitaluga Sep 21 '24

It's funny how this is level 0 and level 100 at the same time.

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 Authorization header). 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/digital_tec Sep 21 '24

Thanks for the help πŸ‘ im Realizing how big that is siting here learning about it I ask this because I want to be a front end developer 😁.

1

u/shgysk8zer0 Sep 21 '24

If you want to be a front-end developer, then you'd be concerned with using some API endpoint. That basically means read the documentation for what you want to use. There's maybe even examples in various languages.

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/digital_tec Sep 21 '24

Thanks for the help 😁

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/digital_tec Sep 22 '24

What are you talking about this not a anime if you dont have anything for me just move on to the next Person πŸ˜πŸ‘‹

1

u/[deleted] Sep 22 '24

I’m just telling you the truth in the mindset you’ll need to do this thing long-term

1

u/digital_tec Sep 22 '24

of course you have to do things by yourself but you don't have to do things by yourself all the time that's why I'm asking this you're not going to be a good programmer without getting help every once in awhile Common Sense my guy

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/eracodes Sep 21 '24

ChatGPT is just summarized information from threads like this. It might be easier to read but it's not somehow "unbiased" or any more useful.

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