Jump to content

API questions

Joelbanks5

What is an API? What does it do? Another topic I'm fairly clueless on, making your own questions and answering them would be nice to help me understand. thanks

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, P4ZD4 said:

 

 

I've watched that like 5 times now and I just don't feel like I'm getting it.

Link to comment
Share on other sites

Link to post
Share on other sites

Well if i was to give a really simple example its like ordering delivery, the API is how you order, the API documents are the menu you order from and what you get delivered is the functionality the API service provides.

 

Its a set of "standards" so someone can use a service someone else is providing. As an example the Google Drive API provides developer way to interact with with the user's google drive to store, retrieve and modify files. So the API is the "standardized" interface the developers work with to extend/use those functionalities.

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, P4ZD4 said:

Well if i was to give a really simple example its like ordering delivery, the API is how you order, the API documents are the menu you order from and what you get delivered is the functionality the API service provides.

 

Its a set of "standards" so someone can use a service someone else is providing. As an example the Google Drive API provides developer way to interact with with the user's google drive to store, retrieve and modify files. So the API is the "standardized" interface the developers work with to extend/use those functionalities.

 

I'm asking the wrong questions. sorry

 

So how do devs see an API and what do they do with it? 

Link to comment
Share on other sites

Link to post
Share on other sites

2 minutes ago, Joelbanks5 said:

I'm asking the wrong questions. sorry

 

So how do devs see an API and what do they do with it? 

 

It's a programming interface so what the devs see is a set of methods they can invoke using some parameters and that makes the API needs to do that task. So what the devs do is they search for the API docs(the manual) of the API they want to use and choose what method they're going to use to get something done (example).

Then all they need to do is call that method (in this example using a url).

 

Its kind of hard to explain unless you have an basic understanding of how programming work.

Link to comment
Share on other sites

Link to post
Share on other sites

4 hours ago, Joelbanks5 said:

What is an API? What does it do? Another topic I'm fairly clueless on, making your own questions and answering them would be nice to help me understand. thanks

First, you have to understand that in programming, we have what are called subroutines or functions. A subroutine can be executed (called) and given some information to work with (parameters) and it can return a result when it's done (return value).

 

Simple example (not actual code):

Subroutine called Print_something_to_screen ( parameter: thing_to_print)
{
	//Code that prints "thing_to_print" to screen.
}

Main program
{
	call Print_something_to_screen(Hello)
	call Print_sonething_to_screen(World)
}

So we have a subroutine that prints it's parameter to screen and we call it twice from the main program, this will print "HelloWorld". Beeing able to call them over and over is one of the strengths of subroutines, if something needs to be done multiple times we don't write it multiple times, we make it a subroutine and call it multiple times.

 

A API is nothing more then a collection of such subroutines that do various things.

Why do we need API's and not write everything ourselves?

 

-Because we don't want to keep reinventing the wheel. Many common things need to happen a lot and everybody uses them. For example, reading and writing things to a file. So, most programming languages provide a API for file handling so we can just call those functions to open, read and write files.

 

-Because we're not allowed to do everything. Most modern operating systems such as windows are multitasking, many programs run at the same time. That requires programs to behave to certain rules. For example, if my program wants to read/write something to a serial port like COM1, I'm not allowed to use the port directly. Other programs might want to use it aswell or may perhaps already be using it. The windows API has functions that provide access to the serial port and windows acts as the 'referee'.

 

-Because we want abstractions. For example, deep down in the system, reading and writing to files works very differently on different systems. Under the hood, windows and linux, for example, handle files in a totally different way. Because of API's, the application programmer does not have to care. The C API for handling files, to pick one, is standardized so it looks the same on any system. That means the application programmer can always access files with the same functions without caring what system he's on.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×