JoinDownload
This is drafted post. Please setdraft: falsein this .mdx file once ready to be published.

What is SDK? How to create them?

3 Min Read

Vyom Srivastava

What is SDK?

It is possible to completely write your own code from scratch but it would be incredibly tedious and a time consuming process for developers to do this every time they come up with a new idea. I mean imagine having to plant, grow and harvest your own wheat everytime you wanted a delicious slice of bread.

You know about APIs, which is a tool to transfer data between two platforms and making programming a lot easier. But what about the front end interface, the tools that a developer actually sit down and use. Well, these often come in the form of SDK. Think of it as a virtual tool box but instead of hammer, plier you’ll typically find files that are called libraries which are essentially pieces of code that help a program to play nicely with whatever platform they’re on.

For example, libraries in the Windows SDK which allows programs to make calls to the operating system to perform certain functions easily without having to tediously code them manually.

Other common SDK includes visual editors so that a developer can design and layout the graphical elements like buttons and text boxes easily with tutorials and sample codes so that a developer can become familiar with the platform that they’re coding on and debuggers that helps the developers to find the errors and bugs in their code.

But SDK aren’t just limited to making programs on Windows. An individual SDK is heavily customised for their platform such as the Cosmo SDK from robotics company Anchy which can be used to train their robotic camera for facial recognition and special awareness, animate the robot to say or do certain things or even plan out a movement path which makes it easy for the robot to cross the obstacle. All with just a few lines of code instead of having to create from scratch and become an expert in artificial intelligence.

And you’re not only restricted to use one SDK on only one platform. If you’re looking to create something like next WhatsApp, or Instagram. For example there are a lot of iOS and Android SDKs that specialize in different types of apps. There are chat focussed SDKs that make it easy to send notification or speech bullets.

Well in formal language, SDK stands for Software Development Kit which is used to simplify the communication with the external resources. You can say that SDKs can be APIs but APIs can not be a SDK. In simple words a SDK can be only used to make API calls but API can not call SDK functions.

Now let us try to create our own SDK using SpaceX API. Why SpaceX API? Because it is a public API and doesn’t need you to create an account or authenticate which becomes one of the easiest API that can be converted to SDK. So, we’ll use NodeJS here.

Prerequisites:

  • Knowledge of APIs
  • Knowledge of NodeJS

Step -1: Environment Setup:

Open your terminal and create a new folder.

mkdir spacex

Once done, let us initialize a project using

npm init

Once everything is done let’s create a file spacex-sdk.js.

Step -2: Creating modules and API functions

Once the Step -1 is done, open the file that you created and paste the below code:

var axios = require('axios');
var channels = async function() {
var config = {
method: 'get',
url: 'https://api.spacexdata.com/v3/capsules',
headers: {
'Cookie': '__cfduid=d0d0a49c1041a0944dad3daf90b9b462c1615234237'
}
};
var data = await axios(config)
.then(function (response) {
return JSON.stringify(response.data);
})
.catch(function (error) {
console.log(error);
});
return data;
}
module.exports = {
channels : channels()
}

Next, install axios to make the API requests. So, on your terminal paste the below code:

npm i axios

Code Explanation:

We have installed one dependency that is Axios. It is a REST API client or you can say package to make API requests in NodeJS. So, we’re using this package to make API requests to the SpaceX API.

After that, we’re making a GET request to the SpaceX API and returning the JSON which we’re getting back. We have created an Async function so that we wait for the API to respond then return the data.

Step -3: Testing the SDK

Now create another file test-sdk.js and paste the below code:

var spacexFunctions = require('./spacex-sdk')
const getData = async () => {
var data = await spacexFunctions.channels
console.log(data)
}
getData()

Code Explanation:

We’re importing the SDK in our test file under the variable spacexFunctions and then creating an Async function under which we’re waiting for the response from the channels function of SDK.

To execute the code use the below command:

node test-sdk.js

On execution, you should get something like this:

sdk

Final Words

Developing an SDK is a challenging job. You’ll have to maintain each version of SDK separately as they’re completely language-dependent but at the same time gives the developer a lot of flexibility and saves time. You can use it with anything and not only restricted to the APIs. There are a lot of SDKs out there which reduces a lot of hard work for the developers so that they can focus on their main goal instead of messing up with writing everything from the scratch.

CONTENT
What is SDK?Prerequisites:Step -1: Environment Setup:Step -2: Creating modules and API functionsStep -3: Testing the SDKFinal Words

Links

DownloadDocChange LogsCookiesTerms & ConditionsPrivacy PolicyContact Us

Apps & Integrations

HTTPGraphQLWebsocketSocketIO

Firecamp Newsletter