Using '(e)' in functions?

You have, you’ve been using APIs constantly. They are the interface through which you, when you’re programming, interact with the system.

1 Like

Hahaha ohh I see! So when people are speaking of, for example a “twitter API” they are basically referencing the library that allows them to interface with twitter through code?

Its kinda like a giant script with bits you can input data and manipulate to a degree? :thinking:

You might be referring to a REST API (RESTful API), which isn’t quite the same (still an API though). API = Application Programming Interface.

An API is just an abstraction build to interface with the code and data. A stupid simple real-world analogy might be saying a doorknob is an API for a door.

1 Like

ok im confused :sweat_smile:

so is

this correct?

^This makes a lot of sense to me though :thinking:

Well, yes, as @lasjorg says you may be thinking of REST APIs. There is a rest API for Twitter. But they are how you interact with a server designed using a set of principles called REST, what the request URLs need to be like to get or send specific bits of data from/to the server.

Well, yes I guess so.

API for React is stuff like

React.useState
React.createElement
React.Fragment
...etc

API for JSX is stuff like

<Component someProp={someVariable} otherProp="some string" />
<button type="button">Press Me</button>

Browser JS APIs are stuff like

fetch("https://some.url")
document.querySelector(".some-class")

JS API for, say, the Array type includes stuff like:

myArray.push("something");
[1,2,3].map((num) => num * 2);

…and so on. It’s basically what you’re using when do use anything in programming. Like a browser: it provides a JavaScript API so you can do things in it. Every type of thing (arrays, objects, strings) in JS has an API. JavaScript itself at base level is an API for whatever you’re programming regardless of if it’s browser or not. Then every library for the browser builds on that API and provides an API of its own. And so on and so forth.

1 Like

You are allowed to be confused, I think it is safe to say that API is a very broadly used term.

It does work, maybe just a little simplistic.

But believe it or not, doorknobs actually suffer from some of the same abstraction issues that an API can. When you see the door can you tell by looking at the doorknob if you are supposed to push or pull? Or did someone just put a sign up saying “Push”, because otherwise people just stand there looking silly as they try to pull on the handle? A well-designed doorknob will signal intent and communicate its usage. Just like a well-designed API should.

OK, I think maybe I have taken that analogy as far as it can go. :stuck_out_tongue:

3 Likes

Hahaha your analogy is brilliant I can tell! I just wish I could fully understand the depths of its reference :rofl:

Im watching this video now. It helps a lot, but this stuff is pretty abstract for me. I think I’ll have to eventually connect a google maps API or something to finally get it.

With code, it often comes down to naming things well and putting them in the correct place.

Array.push()
Array.pop()

Pretty good, the location is correct and the names make sense.

Array.shift()
Array.unshift()

Less great, in my opinion. The location is correct, but if you still after having coded in JS for some time have to think twice to remember which of the methods does what, the naming might not be all that great. Or maybe it’s just me, who knows.

2 Likes

An API is how a programmer and/or a computer interact with a system. To keep stretching the doorknob analogy, you could not have a doorknob. People would have to try to figure out how to open the door themselves. Someone might use a crowbar, someone else might nail a makeshift handle on to open it, someone else might just smash the door.

To pull it back across to programming APIs, you could not have a browser API. You could just give them the uncompiled source code of a browser and tell people that if they wanted some functionality, they could just add it to that and build their own version of the browser. Or in JS you could not have special APIs for, say, strings. Instead of being able to use toUpperCase or replace or whatever, you would have to manually loop over a string every time you wanted to do anything. Etc

Edit: hahaha, yes I get that as well @lasjorg , I have to look it up almost every time I use those methods. And I think the names come from Perl, which was written by a linguist, so you’d maybe expect them to be a bit better…

Though I guess it does “shift” the array right

2 Likes

@DanCouper I’m sure it is supposed to make sense, it just never seems to stick with me.

For me, I have to use process of elimination. If I can just remember that unshift adds something, I can pretty much figure it out from there (I know it’s not push and I know it’s not removing anything so it must be adding it to the front).

2 Likes

Ah, I’ve even got it wrong there, because shift removes…I was thinking "well shift sort of moves everything sideways to the right…aargh

1 Like

So anytime you’re using a method you’re accessing an API? Is that also true with but in functions and keywords since they are interfacing data?

Seriously thinking about getting it now. I probably will. Thanks for the insight, its super helpful because I initially Really wanted to get it but as I said above; I only decided against it because of the negative reviews. But since you guys had a positive experience with it, its definitely encouraged me to give it a second shot.

Well, yes. But you aren’t accessing an API, that doesn’t really make sense. You don’t access an interface. An interface is the point at which one system (for example, you) interacts with another system (for example, a computer, or something higher level running in the computer).

So an application programming interface is normally the thing you program against. JavaScript itself is essentially an API wherever it is used practically. When someone writes code that that will be used by other programmers and by computers – for example, they are writing a language, or a part of the standard library for a language, or any library, or any class, down to any single function, or they are writing the way you interact with a program or application or device or remote system or whatever – there has to be some sensible way of using whatever they’ve written. An API. Here’s the React API, for example:

2 Likes

Got it. That now makes sense. I guess what’s (not confusing but…) hard to imagine is what an API looks like. Like what is it?

Is an API a script file? or…

Guess I can start by asking what’s the file extension for an API?

Is it hard to build an API?

… I’ll check out that link you’ve posted now :face_with_monocle:

No, it’s not a special thing with a special file extension. It’s literally the functions or objects or whatever that some library or programming language or application exposes. Like, look:

const DansFunctions = {
  sayHi(name) {
    return `Hello ${name}!`;
  }

  sayBye(name) {
    return `Bye ${name}`;
  }

  whatsTheTime() {
    const dateTime = new Date();
    return `The time is ${dateTime.getHours()}:${dateTime.getMinutes()}`;
  }
}

So like, the API for the complex library above is:

DansFunctions.sayHi("some name")
DansFunctions.sayBye("some name")
DansFunctions.whatsTheTime()

That’s just some functions written in JS :man_shrugging:t3:

The link I posted is just a list of the functions and classes that React provides, that’s all

Edit: to use React as an example. There is a lot of code in the React codebase. Lots and lots of functions and classes and objects and whatever else. But the functions on that page, the ones you use if you are writing some React code, they’re the ones it exposes (by expose, it’s JS, there’s [again, literally] a file in the codebase that exports some stuff, then in your files you import that stuff, or the bits you want to use in a particular file).

2 Likes

WOW ok that’s crazy! They make it so much more complicated. Ok I GET that.

So are all API’s basically in the same syntax (if written in the same language)?

Ive seen this Dominos API . I kinda understand it :face_with_monocle:

So basically, it’s just plugging in data into the code (which is considered the “API”)? :man_shrugging:

for example

order.payments.push(myCard);

Where is it pushing the info to? With this API, what is tracking the information? What is it connecting to once all of the data is inputted?

How would you submit or “run” an API like this (asking for a friend) :thinking: :sweat_smile:

Sorry for posting so much.

I really want to do this now :sweat_smile: Im not sure how to get it up and running though. I found a video on YouTube

He’s using the same website to copy the API but since the posting of the video, the code has been updated and I believe it works slightly different.

For some reason, the code won’t run in node. I keep getting an error.