What is an API (Application Programming Interface)
API is consists of a specific set of rules/guidelines/logic of the application.
- It helps us to interact with two Softwares/Apps.
- We will use API’s to simplify the complexity.
Example: Searching for an Email based on sent To address.
API Code snippet for search email:
Mailosaur client = new MailosaurClient(“YOUR_API_KEY”);
SearchCriteria criteria = new SearchCriteria();
List<MessageSummary> results = client.messages().search(“SERVER_ID”, criteria);
MessageSummary latestEmail = results.get(0);
Here we are using existing Mail API to establish connection and to check email messages. The current Mailosaur API is a generic API for all.
API and HTTP
API needs HTTP for transport data over the internet.
- HTTP(Hypertext Transport Protocol) is an application layer protocol that is used to transmit the data between two different systems/hosts over the network.
- HTTP is a stateless protocol – Doesn’t care about an earlier request
Web API is required the internet to interact with applications.
- All API’s are not required to be web API’s as we also have native API’s like webdriver API(selenium).
How HTTP Request and Response works
- HTTP communication should happen through TCP (Transmission Control Protocol) /ip connection. It means client and server should have a qualified IP address (32 bit) and Port(HTTP:80 and HTTPS:443)
HTTP Request and Response Process
- HTTP will initiate a connection between the source and destination systems.
- Client Send a request to the server through HTTP protocol
- Server processed the request and send back a response
HTTP Get Request
HTTP Get Response
HTTP Response Codes
Sample Request methods
- GET : Accessing facebook Login Page
- POST: https://www.facebook.com/ register
- DELETE: Deleting file from trash
HTTP vs HTTPS
- HTTP is not secured when we want to use sensitive data on internet.
- HTTPS is more secure to use as its encrypt the data during transit phase.
- We use SSL(Secure Sockets Layer)/TSL(Transport Layer Security) digital certificates at webserver to make use of HTTPS protocol.
SOAP and REST APIS
- SOAP (Simple Object Access Protocol) is a protocol.
- REST (Representational State Transfer) is an architectural style.
- REST can also use SOAP protocol to develop a specific functionality.
- SOAP API uses WSDL (Web Services Description language) for describing the functionalities.
- Enterprise applications uses WADL (Web Application Description Language) to define rest apis functionality.
- The Web Application Description Language (WADL) is a machine-readable XML description of HTTP-based web services.
SOAP Request and Response Format
SOAP Vs REST
Most popular tools for API Automation
- REST-Assured: It is really good when you have good number of regression test cases which is fall under behaviorial driven scenarios.
- Postman : It is mostly used when you want to automate smoke tests.
- SOAP UI: It is useful when we have complicated functional scenarios.
Happy Learning 🙂