DEV Community

Cover image for APIs Unveiled: Interview Edition! How Have You Worked Your Developer Magic?
Ben Halpern Subscriber for CodeNewbie

Posted on

APIs Unveiled: Interview Edition! How Have You Worked Your Developer Magic?

Let's unravel the mysteries of APIs! This topic often makes an appearance in technical interviews. Can you break down the concept of Application Programming Interfaces (APIs) in simple terms? And, more importantly, share a cool project where you've flexed your coding skills by integrating an API?

Newbies and experiences DEVs alike, please weigh in so we can compare notes! How would you answer - or how have you answered - this question during an interview?

Follow the CodeNewbie Org and #codenewbie for more discussions and online camaraderie!

Top comments (6)

Collapse
 
gaurang847 profile image
Gaurang • Edited

This is a great question! When I first heard about APIs in college, I just could not understand what they are. I understood them only after I actually started working with them.
So here's my attempt to explain it.

An API is basically a means to interact with a back-end service.

Say for example, there is a calculator service that can take an expression and calculate it's result.
How do we use this service? How do we ask the service to calculate "1+4"? And how do I get the result?

One way to do this would be by using an API.
Suppose the service is available at www.mycalculator.com. Hopefully the developer of the website would have been kind enough to create an API for the service - www.mycalculator.com/calculate.
You may pass your query to this endpoint as www.mycalculator.com/calculate?query=1+4, and put it in your address bar. Press "Enter" and you may see a page with a 5 written on it.

Under the hood, there is a process running the calculator service on a server.
When you put www.mycalculator.com/calculate?query=1+4 in the address bar, a network call takes place between your browser and that server running the calculator service. We call this network call an API request.
The calculator service understands that it is supposed to calculate "1+4" and it returns "5" back to your browser. This is called an API response.

I hope this explanation gives a rough idea about APIs to anyone who's new to programming. There's a lot more to APIs and I've barely touched the surface.

Here's a sample project which I had created many years back; while learning back-end web development using Node.js.
It's a simple login service that has APIs for sign-up and login.

GitHub logo gaurang847 / NodeJS-Playground-Login-Service

Login System in NodeJS using ExpressJS.

NodeJS Playground - Login service

Login System in NodeJS using ExpressJS.
Do check out the wiki to read about the stuff that I learnt through my journey.

Dependencies:

  1. expressJS
  2. Sequelize
  3. body-parser
  4. jsonwebtoken
  5. cookie-parser
  6. bcrypt

You can install all of them using:
$ npm install express sequelize body-parser jsonwebtoken cookie-parser bcrypt

Also, any one of the following according to your needs:
$ npm install --save pg pg-hstore
$ npm install --save mysql2
$ npm install --save sqlite3
$ npm install --save tedious

Login System consists of following APIs:

  1. POST /user : This api will help with user registration process. A user is defined by the following attributes:
    a. user_id (primary_key)
    b. first_name
    c. last_name
    d. email
    e. mobile_number
    f. password

  2. POST /login: This api will have mobile_number and password as post request body and upon password validation will return JWT.

  3. GET /user: This api will be use to get…

Collapse
 
jmplourde profile image
Jean-Michel Plourde • Edited

My simplest explanation of an API: it's a set of protocols and rules for two systems to communicate, exchange data or perform action while abstracting a lot of the complexity.

I don't have project to showcase, but I am currently working on a project in Python that has a Django webserver and we use Django REST framework to expose an API of our system. It is used for our web pages as well as our mobile application.

The main challenges are making the API intuitive to use, following the REST principles and making changes while staying retrocompatible with clients using an old version of the API.

Collapse
 
jmfayard profile image
Jean-Michel 🕵🏻‍♂️ Fayard • Edited
  • I remember you showed me you have a cool weather app on your smartphone.
  • Yes! xxx has an incredible design, I love it!
  • But how do they know that the temperature in Berlin tomorrow will be 28 degree celsius - or 82 in freedom units?
  • Mmh I'm not sure... The app is not done by Eumetsat so they probably don't have their own geostationnary weather satellite.
  • Right
  • Maybe they hire meteorologists to make the previsions? .... No that can't be, that's not the core of their business. They have the same temperatures as anyone else.
  • So the information has to come from somewhere else?
  • I think so yeah. But where?
  • From an API of a weather company. For which it is indeed their core business to know when where what temperature it will be.
  • That's cool. An API you say?
  • Yes, see Wikipedia: Application Programming Interface
Collapse
 
miracool profile image
Makanju Oluwafemi

Let's of APIs (Application Programming Interface) as a way for different software applications to communicate with each other and work together. Just like how people use languages to communicate and understand each other, APIs provide a common language for software programs to interact share resources and perform operation within themselves.

Imagine you went to a restaurant and you want to order some food. You don't need to go into the kitchen and ask for the available meals. Instead, you communicate with the waiter or waitress, who takes your order to the kitchen and brings you the food when it's ready. In this scenario, the waiter or waitress is like an API. A communication mechanism between you and the kitchen.

Similarly, in the software world, an API acts as a waiter or waitress between different applications. It receives requests or orders from one software program and passes them on to another software program that can fulfill those requests usually between frontend and backend of an application. The backend processes the request, performs certain actions, and sends back a response to frontend through the API. This way, the frontend doesn't need to know the nitty-gritty details of how the backend works; it just needs to know how to communicate with the API.

In conclusion, APIs enable different software programs to interact and work together by providing a common language or interface. They simplify the process of integrating different applications and allow developers to leverage the functionality of other programs without having to understand all the underlying complexities, Amazing if you ask me.

You can check this forum site, I created recently for a school project
here
Thanks for reading...

Collapse
 
nlxdodge profile image
NLxDoDge

To me an API is more like an extension of a library that you want to use, but couldn't be done locally for X reason.
Mainly data or performance, for example if you ever need to scale up and make micro-services or you cannot just freely connect with a database from some other company. They most likely make an API with some security and logging.

As a Java Dev Ops Engineer I am working with a lot of Spring Boot applications at our company, the interfaces are somewhat simple but the complexity behind the API itself are huge.
For example, getting two IBANS (from and to in an online bank transaction) and then checking all supplied data/getting more data and returning a list of products that can be used. That API alone already gets 30+ requests per second!

Collapse
 
tbroyer profile image
Thomas Broyer

Funny how everybody seems to jump to the conclusion that we're talking about remote APIs whereas that wasn't made explicit.

An API is first and foremost how your interact with a piece of code, whether in-process as a library, or out-of-process (local or remote).