Skip to main content

How to use API's (For Beginners).

Nicolaas Nel

Nicolaas Nel

Lead Front End Product Developer @ InfoSlips

IDE#

The first thing you will need is the foundation of every developer, an IDE (Integrated Development Environment). My recommendation is Visual Studio Code however you can use any IDE that you personally prefer.

Git#

Git is your best friend as a developer, what is Git? Git is a version control manager. It basically makes sure you don't lose anything you've done and it also allows you to store your code on Github and to clone other peoples projects from Github.

You can download Git here: https://git-scm.com/downloads

NodeJs#

Node JS is super important, this helps you install all sorts of packages to help with development, it also comes with a package manager called npm (node package manager) which you will use a lot.

You can download NodeJS here: https://nodejs.org/en/download/

Getting Started:#


Git Clone#

Get the base project from my Github to get started, this repo also includes reccomended extensions to make coding/testing easier. To clone the repo open up your terminal and execute the following command:

git clone https://github.com/NicmeisteR/Tutorial-Api.git

Extras:#


Issues Forks Stars Size Tweet

Community#

Community

Donate, Support or Fund#

If you love this project please consider donating or support the development by means of coffee. You may also fund this project to maintain active and close more issues. Just a cup of coffee is enough to appreciate our hardwork.

Donate Support

Author#

Node Essentials is Developed and Maintained by Nicolaas Nel

Facebook Twitter LinkedIn YouTube DEV


Made with ๐Ÿ’™ and โ˜• by Nicolaas Nel.

Node-Essentials

Nicolaas Nel

Nicolaas Nel

Lead Front End Product Developer @ InfoSlips

Late last night I decided to finally publish my very own npm package, it's something I've wanted to do for a while now and I could never decide what to package.

While brainstorming I was busy working on a node.js app to process some data, the same code I've used in several projects.

This was it, the perfect package. I don't like searching for stuff I've already used and will use again in the future so I decided to package my most used node functions into a lightweight npm package.

To my surprise in under 10 hours it already hit over 800 downloads!๐Ÿฅณ

About Node-Essentials ๐Ÿฑโ€๐Ÿ#

This is a nodejs toolkit for doing asynchronous api calls, writing files to the system, starting up express-js servers and more coming soon.

Setup ๐Ÿšง#

Run:

npm install node-essentials

And include it in your app:

let node = require('node-essentials');

Current Tools โš™#

writeToFile - Writes anything passed through to storage as any file.#

The below sample is used to print out json data from an API call.

node.writeToFile("tests", "writeToFile", "json", JSON.stringify(data));

express - Set up an express-js server on the specified port and directory.#

The "__dirname" is the relative path for the directory used by node and 3000 is the port it will serve to this is also the default express port. This would serve the current root directory.

node.express(3000, __dirname);

get - A simple Async REST "get" request.#

I will be adding more rest functions soon.

async function get() {
try {
test = await node.get(
"https://apiurlhere.com/",["api key desc", "api key value"])
.then(console.log("done"));
}
finally {
console.log(test);
}
};

Conclusion ๐Ÿ#

The package contains functions I commonly use, I will be adding more simplified essential tools/functions as time goes on!

It's been an interesting journey making my first package and any feedback/suggestions of functions to add would be welcomed.

Where to get the package#

NPM Github

If you want to keep track of all my projects and endeavors I am super active over on Twitter and I'm always happy to give advice and lend some help.

FinalNecessity on Twitter ๐Ÿฃ

GraphQL - NodeJS

Nicolaas Nel

Nicolaas Nel

Lead Front End Product Developer @ InfoSlips

For a while now I've wanted to jump into the deep end of GraphQL and see what all the fuzz is about.

And oh my I wish I did it sooner.

So, what is it?#

GraphQL is A query language for your API, this gives you the ability to ask for exactly what you need from the API and nothing more.

Why should I use it?#

This is something that works amazing for big API's like the Halo 5 Game API that I used in my example.

A normal player has about 20 000 lines of data but for most of the calls I make I only use a fraction of that (24 to be exact). Reducing my calls to only get what I need gives me a big performance bonus and I'm able to use less data on the client side.

Returning a smaller JSON object makes coding on the front end a lot easier than previously.

// Sample of Possible Queries
let queryObjectSample = {
Gamertag: String,
Xp: Number,
SpartanRank: Number,
HighestCsrAttained: {
Tier: Number,
DesignationId: Number,
Csr: Number,
PercentToNextTier: Number,
Rank: Number
},
Stats: {
TotalKills: Number,
TotalHeadshots: Number,
TotalMeleeKills: Number,
TotalAssassinations: Number,
TotalGroundPoundKills: Number,
TotalShoulderBashKills: Number,
TotalPowerWeaponKills: Number,
TotalDeaths: Number,
TotalAssists: Number,
TotalGamesCompleted: Number,
TotalGamesWon: Number,
TotalGamesLost: Number,
TotalGamesTied: Number,
TotalGrenadeKills: Number,
TotalSpartanKills: Number,
},
TotalTimePlayed: String
}

Here is a sample of what I return opposed to the 20 000 fields:

{
"data": {
"Gamertag": "NicmeisteR",
"HighestCsrAttained": {
"Csr": 1872,
"Rank": 78
},
"Stats": {
"TotalKills": 34834,
"TotalDeaths": 31017
}
}
}

To get the above data all I have to do is make an API call to my Express NodeJS server and with the below query to retrieve what I need.

var dataString = {
"query":
`{
Gamertag,
HighestCsrAttained {Csr, Rank},
Stats { TotalKills, TotalDeaths}
}
`};

How to get started#

Go over to GraphQL and select your language of choice and follow through with the tutorial.

GraphQL is super scalable and flexible.

Alternatively you can also check out my Github Repository GraphQL-NodeJS to get straight into the action and see how it all comes together.

Conclusion#

GraphQL is something I would high recommend checking out, although it's still relatively new a lot of employers are on the lookout for people with knowledge around it.

Check out the repository for the project here: https://github.com/NicmeisteR/GraphQL-NodeJS