DEV Community

loading...
Cover image for What exactly is API?

What exactly is API?

anubhavitis profile image Anubhav Singhal ☃️ ・3 min read

APIs are one of the most significant parts of software development, every developer must be well versed with them. I have been working as a golang backend engineer for about a year now, have constructed plenty of APIs for various projects.

Recently, I came through an interesting session on APIs at Crio: Learn by Doing and am sharing its notes with DevCommunity. Let's get it started!


What is an API?

API stands for Application Programming Interface, is a set of functions that allows applications to access data and interact with external software components, operating systems, or microservices.

In simple words, an API is like a waiter in a restaurant. You don’t go into a cafe and walk straight into the kitchen to tell the chef what you wanna eat. The waiter does that for you, and that’s exactly what an API is - with the client being you, the customer, and any resource that can send data, being the chef.


Benefits of using APIs

  • Security: While using an API, client-side and server-side application works independently, and they communicate through API, so if anyone tries to hack into the client-side app, the server stays unaffected and secured.

  • Flexibility: APIs allow content to be embedded from any site or application more easily. For e.g. an API written in GO can be used by Node.js/Django.

  • Efficiency: When access is provided to an API, the content generated can be published automatically and is available for every channel. It allows it to be shared and distributed more easily.

  • Innovation: With an API, an application layer can be created which can be used to distribute information and services to new audiences which can be personalized to create custom user experiences.


REST API

REST stands for Representational State Transfer, it is the most popular web API architecture. They follow a client-server model where one software program sends a request and the other response with some data.

These APIs generally receive a response in JSON format, it's a standard format that is easily "understandable" by applications and can be handled well in most languages. For e.g. Ruby app can easily use JSON response from Java sever.

JSON stand for JavaScript Object Notation, it is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate. Read more about it here

There are several other forms of APIs (SOAP, XML-RPC, JSON-RPC, etc.), we'll limit our discussion to REST only. For more info, Click here


REST != HTTP

A lot of people prefer to compare HTTP with REST. REST and HTTP are not same.

In the REST architectural style, data and functionality are considered resources and are accessed using Uniform Resource Identifiers (URIs). The resources are acted upon by using a set of simple, well-defined operations. The clients and servers exchange representations of resources by using a standardized interface and protocol – typically HTTP.

Resources are decoupled from their representation so that their content can be accessed in a variety of formats, such as HTML, XML, plain text, PDF, JPEG, JSON, and others. Metadata about the resource is available and used, for example, to control caching, detect transmission errors, negotiate the appropriate representation format, and perform authentication or access control. And most importantly, every interaction with a resource is stateless.


API Request & Response

REST API request generally consists of Method, Body(auth and other parameters), and Host. Here is a sample request that I have been working on recently.

As stated earlier, REST API responses generally in JSON format. Here is a sample response to the above API requests.

Note: To get a similar response from the previous request, you'll have to add an API key: and API secret.


For more information, goto reastfulapi.net

I hope you have a good understanding of APIs now. If this article helped you, support it, and share it among your peers.

Connect with me: LinkedIn | Twitter | GitHub

Happy Coding!

Discussion (15)

pic
Editor guide
Collapse
margo_hdb profile image
Margo McCabe

This is super interesting thanks for sharing! We're actually hosting a workshop in a couple weeks where you can code along to build a REST API, in case you have any interest.

Collapse
rudrakshi99 profile image
Rudrakshi

Amazing article!

Collapse
anubhavitis profile image
Anubhav Singhal ☃️ Author

Thanks, Rudrakshi!

Collapse
ritvikdubey27 profile image
Ritvik Dubey

Thanks for writing. Found it very helpful 🙌

Collapse
anubhavitis profile image
Collapse
akshayvarshney6 profile image
Akshay Varshney

Very well done Anubhav!!!

Collapse
anubhavitis profile image
Anubhav Singhal ☃️ Author

Thanks for supporting, Akshay!
Really appreciate it.

Collapse
realtoughcandy profile image
RealToughCandy.io

This article is a good reference point for beginners. Well done.

Collapse
anubhavitis profile image
Anubhav Singhal ☃️ Author

Thanks a lot.
Glad to hear that for sure!

Collapse
rishitkhandelwal profile image
Rishit Khandelwal

GraphQL 🥲.

Collapse
anubhavitis profile image
Anubhav Singhal ☃️ Author

For simplicity of beginners, I tried to keep blog more about the idea, and less about the technicality.

Will write a detailed article as well, soon.

Collapse
aadarsh1999794 profile image
Aadarsh kumar

Thanks for sharing very helpful

Collapse
pomfrit123 profile image
***

How can I return an image instead of json?

Collapse
anubhavitis profile image
Anubhav Singhal ☃️ Author

link to image can be returned.

Collapse
aadarsh1999794 profile image
Aadarsh kumar

Thanks for sharing very helpful