Newby Coder header banner

API

What is API or Application Programming Interface

Technically, an API is short for Application Programming Interface, which is an interface of an applicationprovided to allow communication with a client program

An interface is like a method (or coded functionality) of a program or application,which is exposed to a user or a client program

The usage of an application fora user or client, is defined by(and limited to) the interface(s) exposed by it

An interface can be a Command Line Interface, like many commands run on a Terminal or windows command line are interfaces of programs,

or a Graphical User Interface, like any Windows or Linux application which has its own window is an interface to its functionalities

Web or Rest APIs

API is often used to refer to Web or REST APIs of services

A web API is typically defined as a set of specifications, such as Hypertext Transfer Protocol (HTTP) request messages, along with a definition of the structure of response messages, usually in an Extensible Markup Language (XML) or JavaScript Object Notation (JSON) format

For example, Twitter's REST API allows developers to access core Twitter data and the Search API provides methods for developers to interact with Twitter Search and trends data

Many services expose APIs for authenticating into their service

Example

Assume a service provides an authentication API which accepts JSON data such as

{
    "username":"",
    "password":""
}

A client such as a mobile application then creates a HTTP request with this format and passes values of username and password for some user

{
    "username":"user_nc",
    "password":"nc_password"
}

The services then validates username and password, and returns a token on valid authentication

{
    "username":"user_nc",
    "webToken":"js23fsd-3298jfs-nc32kjsf"
}

The client then uses this webToken for subsequent requests to other APIs of the service which require requests to be sent from a valid user

Java Interface

An interface in Java is a an "abstract class" that is used to group methods with empty bodies which are related to it

This class can then be implemented by classes or other interfaces which have to implement all its methods