C
C#3y ago
Metalkon

Is this how all API's work?

https://youtu.be/ZveW4_ZJtVY?t=475 I've always struggled with the concept of what an API actually is in the program since every example has been way too abstract (like restaurant waiters and such) or never showed what it was actually working with. But after watching this video I think i'm finally getting it (url request with information, receive json, etc) but the example is if you're using another's service for your own app/website. Question: Is this how all API's work? Even on ones own website and app speaking between frontend and backend?
2 Replies
Mkp
Mkp3y ago
Application Programming Interface, you can just call it a library. It's a set of code that has a goal. For example, model loading, image loading, etc. The code they expose enables you to do load a model or an image. Here is my math api:
static class Maths
{
public static int Add(int a, int b) => a + b;
public static int Sub(int a, int b) => a - b;
public static int Mul(int a, int b) => a * b;
public static int Div(int a, int b) => a / b;
}

class Vector2DI
{
public double x;
public double y;

public Vector2DI()
{
}

public Vector2DI(double x)
{
this.x = x;
}

public Vector2DI(double x, double y)
{
this.x = x;
this.y = y;
}

public double PythagoreanTheorem()
{
return Math.Sqrt(x * x + y * y);
}

}
static class Maths
{
public static int Add(int a, int b) => a + b;
public static int Sub(int a, int b) => a - b;
public static int Mul(int a, int b) => a * b;
public static int Div(int a, int b) => a / b;
}

class Vector2DI
{
public double x;
public double y;

public Vector2DI()
{
}

public Vector2DI(double x)
{
this.x = x;
}

public Vector2DI(double x, double y)
{
this.x = x;
this.y = y;
}

public double PythagoreanTheorem()
{
return Math.Sqrt(x * x + y * y);
}

}
Your operating system has an API for interfacing with hardware. What implements the API are called Drivers.
Monsieur Wholesome
My guy talked talked about web apis, and you come around drilling in "apis can just be called libraries" A Web API is just a web server that, when asking specific endpoints (endpoints being certain url paths), you get data back. 95% of the time, when talking about Web APIs, it's usually actually data-oriented, so you CRUD (create, read, update, delete) certain data (What you described yourself with CRUD'ing waiters/waitress) But depending on the context, you could also say that normal website endpoints (https://www.youtube.com/c/Certbros) are a kind of web api Answer: Yes, the frontend ideally does the requests to Web API endpoints the backend has
Want results from more Discord servers?
Add your server