What is API

Ultimate API guide

Contents

Application Programming Interface: allows two applications to talk to each other

REST (Representational State Transfer): A set of functions for developers to perform requests and receive responses using HTTP protocol

  1. API Documentation (need endpoint, parameters, resources, data)
  2. Access to DB (Validate response by comparing response to DB)
  3. Authorization overhead (Handle tokens)
  1. HTTP request methods
  2. URI
  3. Resources and parameters
  4. Request header (JSON, XML)
  5. Request body (message content)
  • Payload/body is secured input data sent to API
  • In JSON
  • JavaScript Object Notation
  • Data format represented as String-text
  1. Session/Cookie based Authentication
  2. Basic Authentication
  3. Digest Authentication
  4. OAuth

API testing is:

  1. Light-weight
  2. More stable than UI testing
  1. Verify the accuracy of data (if is as expected)
  2. Check HTTP status code
  3. Response time
  4. Error codes if API return errors
  5. Check Authorization
  6. Non-functional testing
// below is an API request URL
http:/abcd.com/orders/11234?location=IND

// End point: http:/abcd.com
// Resource: orders

After / : path parameter

After ? : query parameter

API: back-end

UI: front-end

Simple Object Access Protocol: it is a XML based message protocol

Serialization: Convert Java obj –> JSON (Request body/payload)

Deserialization: Convert JSON –> Java obj

courses[0].details.site

Python:

1
2
3
import requests
r = requests.get("https://www.pythonhow.com/real-estate/rock-springs-wy/LCWYROCKSPRINGS", headers={'User-agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:61.0) Gecko/20100101 Firefox/61.0'})
c=r.content

Dart:

1
2
3
4
5
final response = await http.post(url, body: json.encode(requestModel.toJson())); 
print(response.headers['set-cookie']);
print(response.statusCode);

final response = await http.post(url, headers: {'Authorization': token}, body: json.encode(requestModel.toJson())); 
No comment yet.
Powered By Valine
v1.4.14