API — Application programming interface

Vineetha Wijayakoon
What is a RESTful API for beginners
3 min readMar 10, 2019

The API is basically a code which is written by someone else and other persons are able to access its functionalities.Technically, the API is used when two software applications exchange data each other.

Google Map API: Google has developed the google map API. Then Uber Company uses that API to get the location.

API Authentication Key/Token key

API token is a unique key which is catered by API to clients so that API is able to authenticate each client.

Difference between API and Web services

All web services are API, but all APIs are not web services.For instance, the client needs to access data in the server. Then, the client uses an API to access the data in the server.

The API is located in another server and the API connects with the server to access data and the API is available as jar files. However, the web service is used to make available this API to the client on the internet.Then, this API is available as a service to the customers. So in this context, this API is called a Web Service.

What are the types of web services?

1. SOAP

2. REST

SOAP is a protocol and REST is an architecture.

REST web services can call SAOP web services, but not vice versa. Because SOAP is a protocol

Java API JAX-WS is for SOAP web services and Java API JAX-RS is for REST web services

SOAP web services can communicate with systems via only XML data format, however, REST web service can communicate with systems via XML, JSON, TEXT data formats.

SOAP uses WSDL to expose business logics and REST uses URI to expose business logics

URI — End point URL + Service URL (http://abc.com + /wiki/contents/2)

How to identify the objects (resources) exposed in rest web service

The consumer (Rest client) should use the relevant URI and methods to access a particular object (resources) in REST web services.

Methods: Get (R), Put (U), Post ©, Delete (D), these operations are called CURD operations

Example: The objects of library applications are books and users etc.

Rest Client tool for testing purpose: Postman, Rest Assured, SOAP

Technically, the consumer sends HTTP request to access the API.

This HTTP request passes three factors to API:

URI

Headers

Payloads (JSON/XML) : GET requests have no payload.

Then, the server sends the response to the consumer and it includes

Status code

Payload

String message

Query parameter

The REST web service clients use URI concept to communicate with REST API web services.

The query parameters are used to filter the requests and query parameter indicates with a question mark. http://abc.com/contents?title=test

If multiple filtering conditions are sent to API, the query parameter should be

http://abc.com/contents?title=test,selenium&project=automation

HTTP Request Methods

The rest clients use GET, POST, PUT and DELTE http methods to perform the operations on API.

GET method is used to fetch the data from API.

GET http request has no payload and using the query parameters can be filtered response values.

POST method is used to create a new instance in the API side.

POST method has both payload and header

PUT method is used to update the existing data.

PUT method has both payload and header

DELTE method is used to remove the existing data.

DELETE method has no payload. http://abc.com/contents/100

--

--