API vs. SDK: What's the difference?
Tags: api, sdk, difference, restapi
Published: 2021-05-29 02:46:58

# What's an API? What's an SDK?

How are the two related? How can APIs and SDKs help streamline our cloud app development workflows?

Alright, let's get started with an example. Let's say you're developing a mobile app for a photo gallery, and the idea is for this mobile app to allow a photographer to take a picture of a model. The app will communicate with a visual recognition service that's running on the cloud. And the idea is for the service to return the model's name and bring up their details.

So, how do we do this? How do we communicate between the mobile app and this cloud-based service? Well, that's where **APIs and SDKs** come in. Let's get started by talking about **APIs**, and we'll be comparing the two.

## API's

First of all, **APIs** are all about communication.

So, there are many definitions and protocols for apps or services to talk to other apps or services. You can kind of think of them as a bridge between your app and cloud-based visual recognition service.

![API](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ttug67q261aubqh64jcp.png)

#### What does "API" stand for?

Well, it's **Application Programming Interface - A.P.I**. And what are some of the aspects of APIs that make them useful? Well, as I said, they're all about communication. Communicating between a service and another service, an app and another app, it's how they talk to each other.

#### They're all about abstraction.

What does "abstraction" mean? Inside the VR service, up in the cloud, there's probably potentially thousands of lines of code running up there. And you, as a developer of a mobile app you don't want to have to worry about. "OK, which method in the VR service do I call to get the models's name?" You don't want to have to worry about that. So, what an API does is abstracts away all that complicated logic, so you have to worry about getting just the data you need. It simplifies the process.

#### APIs are standardized.

There are industry-defined standards for defining an API, and there are a few formats that are popular for APIs. You may have heard of SOAP, GraphQL, or REST.

> REST stands for "Representational State Transfer."

#### Building blocks of APIs

Request and response forms the building block of APIs.

#### Request

First of all, to send data or send a "request" from the mobile app to the VR service on the cloud, you need to have a few different pieces. So, for a REST API call request, you need to have what's called an operation. So this is this could be HTTP methods like POST, PUT, GET, DELETE. In this case, it would be a POST method because you're sending a request over to the service, which might include something like maybe the like name of the image you took of the model. Finally, would be the endpoint. Which is the URL, basically, of the visual recognition service that you're trying to talk to.

```js
fetch("htttps://fetchmodel.com/getDetails", {
  method: "POST",
});
```

Next would be parameters, which is optional. So, in our case, we might want the file name of the image you took. It may be tina.jpeg. Great, so that's your request.

```js
fetch("htttps://fetchmodel.com/getDetails", {
  method: "POST",
  body: JSON.stringify({ file: "tina.jpeg" }),
});
```

So, this is what makes up a request.

#### Response

How about a response?

What might a REST API response call that you receive back from the visual recognition service look like? Typically it's some form of raw data, maybe JSON. So, a request might look something like this:

```JSON
{
 "name": "Tina",
 "age": 24
}
```

So, you have sort of the above data object that might include the details of the model, and maybe the name - which, in this case, perhaps "Tina" just clicked by the photographer. Great, so that's the building blocks of what an API is.

## SDK's

> As a developer, though, how do you call an API in your code?

You don't want to have to worry about setting up your request with all these building blocks of operations, parameters, endpoints, and dealing with raw JSON objects, right? That's where SDKs come in and shine.

So, let's talk about SDKs. What does that stand for? Well, it is **Software Development Kit**, S.D.K. Pretty straightforward, right?

You can think of **SDK** as a toolbox of tools or code that call APIs for you. Pretty cool, right? So, you may be specialized in one programming language over the other; you know, there are SDKs in various languages. SDK can be in Java, Node, Go, Python, whichever language is your speciality; there's probably an SDK for you.

![sdk](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kyich4z9ipwkbvhe1o6g.png)

Perfect. So, back to our example above, with an SDK, let's go ahead and put our little SDK toolbox within the mobile app and, for this case, since it's a mobile app, say, we'll use the ReactNative SDK. Great!

In the ReactNative SDK, rather than having to configure your request manually with all the building blocks of API, you might call just a method that may be called `getDetails()`. The method will call these various building blocks - the operation, parameters, and request; it'll make it for you, making that API request for you with code. In response, you'll get an answer, but it won't be necessarily a JSON object.

So, the code might look something like this.

```js
const modelDetail = visualRegognisition.scan("tina.jpg").getDetails();
```

So, you have an Analyze Result Object that you call the "Visual Recognition's" `getDetails()` method. You pass in a parameter, "tina.jpg", which is the name of the file you sent over the visual recognition service, and, in response, you get the model's data.

That's the data you received in the form of an object via your SDK, and you're able to Tina was the model whose photograph was taken by the photographer.

Another example of SDK is given below.

```js
var intrinioSDK = require("intrinio-sdk");
const util = require("util");

intrinioSDK.ApiClient.instance.authentications["ApiKeyAuth"].apiKey =
  "YOUR API KEY";
IntrinioSDK.ApiClient.instance.enableRetries = true;

var companyAPI = new intrinioSDK.CompanyApi();

companyAPI.getAllCompanies().then(
  function (data) {
    console.log(util.inspect(data, false, null, true));
  },
  function (error) {
    console.error(error);
  }
);
```

So, hopefully, this summarizes what's an API, what's an SDK, what are both used for, and how they are genuinely fundamental tools in your cloud app development toolbox. If you have questions, please drop me a line below.

If you learned something from this article, please share it with your friends.

You may also follow me on <a href="https://www.linkedin.com/in/prataps22/" target="_blank">LinkedIn</a> and <a href="https://twitter.com/Pratap2210" target="_blank">Twitter</a>.

💌 If you’d like to receive more coding tips and tricks in your inbox, you can sign up for the newsletter [here](https://pratap.substack.com).