1

I did a lot of google searching and none of the explanations give a really basic easy to understand explanation so I'm hoping someone here can really help me understand this.

For this question I'm going to use a project I'm working on written in Javascript. Say I have some code that's going to go into an API and pull data on a toy. The toy has several properties such as price, number of parts, colors, stores sold in, manufacturing date, etc.

I make a request to get the data from the url where this data is stored, say "myapi.com/toy/search?query?=" + toy.

What is the API doing there? What is it storing? Is it storing the data on each individual toy? Or is it just a template of what data the toy SHOULD have and then the data for each toy is stored else where?

Thanks, I'm very new to this so if you see key flaws in my question itself I'd appreciate corrections and clarifications there as well.

Anindya Basu
  • 659
  • 1
  • 6
  • 18
  • What API are you referring to? – ElGavilan May 02 '14 at 18:33
  • 5
    You may find it useful to review what an [API really is](http://stackoverflow.com/a/7440712/1313439). – Daniel May 02 '14 at 18:34
  • One that accesses a database to pull data on products. – Anindya Basu May 02 '14 at 18:35
  • @Daniel after reading that I'm somewhat confused on where those rules are stored, and how they affect the data that I'm trying to access. What happens if data is stored and it doesn't match those rules? Are these rules more like a template that my data must conform to? Like a form? – Anindya Basu May 02 '14 at 18:38
  • The rules are just code. In most cases this code takes the form of a special datatype called a `class`, such as in C++, Java, or Python. Also don't get caught up on the term "rules". Think of an API as a collection of closely related functions that just *do stuff*. Also an API doesn't usually *store* data in itself, it facilitates communication (think of it as code development) between the coder (you) and some other piece of code, technology, or object. – Daniel May 02 '14 at 21:19

3 Answers3

4

Any API has its own set of rules, and you're going to need to consult the specific documentation for the API you're going to use to find out exactly what data it exposes to you and in what formats.

You're misunderstanding what's meant when it's stated than an API is a set of rules. It's not to say that there's a set of rules which a system has to meet to be considered an API.

Rather, the developer of an API provides its users with documentation explaining what one should expect when interacting with their API. That documentation provides you with an understanding of the rules which you must follow to correctly use that particular API.

In short: I could write an API associated with any kind of data I want, and I could store that data wherever I want, and move it around in any format I want.

It's the creation of a set of rules that say "This is the result I promise to serve up in this specific format when you request it in this specific manner" that makes an API.

Sam Hanley
  • 4,707
  • 7
  • 35
  • 63
1

In your case, your are using the API to connect the client application (your javascript code) to the server application (where the data resides).

The server exposes a simple interface (Application Programming Interface) for any client to request an action to be executed on its behalf.

TurboHz
  • 2,146
  • 2
  • 16
  • 14
0

It depends on the context of the API. You are speaking about a REST API. A REST API uses the concept of resources. You should dig deeper into this particular API topic: RESTful APIs.

But APIs have different contexts. Maybe it helps to read about my journey where I experienced these different contexts as concrete examples of APIs. These concrete confrontations put together the bigger picture about APIs for me.

Community
  • 1
  • 1
Robin Wieruch
  • 14,900
  • 10
  • 82
  • 107