API Integration is one of the most important skills for modern developers. APIs (Application Programming Interfaces) connect software applications, enabling them to exchange data, trigger actions, and automate workflows.
This API Integration Cheatsheet helps you understand how APIs work, how to connect to them securely, and how to use them in JavaScript, PHP, Python, Node.js, and cURL.
Table of Contents:
What Is API Integration?
API Integration allows two applications to communicate seamlessly using structured protocols such as HTTP, REST, SOAP, or GraphQL.
For example, when you sign in using Google or fetch live weather data from OpenWeather API — that’s API integration in action.
Core Concepts of API Integration
| Term | Definition |
|---|---|
| API Endpoint | The URL where requests are sent (e.g., https://api.example.com/users) |
| HTTP Method | Defines the action (GET, POST, PUT, DELETE) |
| Headers | Contain authentication, content type, and API key |
| Request Body | Data sent with POST or PUT methods |
| Response | Server’s reply, usually in JSON or XML |
| Authentication | Validates access via tokens, API keys, or OAuth |
api integration cheatsheet, rest api tutorial, api fetch example, axios api call, php api integration, json api request, http headers, oauth authentication, api testing tools, web api development
HTTP Methods Overview
| Method | Description | Example Use Case |
|---|---|---|
| GET | Retrieve data | Fetch user info |
| POST | Create data | Add new product |
| PUT | Update existing data | Edit profile |
| DELETE | Remove data | Delete record |
| PATCH | Partially update | Change single field |
Example: Simple API Call Using Fetch (JavaScript)
fetch('https://jsonplaceholder.typicode.com/posts')
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));
POST Request with Fetch API
fetch('https://jsonplaceholder.typicode.com/posts', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
title: 'Learn API Integration',
body: 'This is a demo post',
userId: 1
})
})
.then(res => res.json())
.then(data => console.log(data));
API Integration Using Axios (Modern JS Library)
import axios from 'axios';
axios.get('https://jsonplaceholder.typicode.com/users')
.then(res => console.log(res.data))
.catch(err => console.error(err));
POST Example:
axios.post('https://api.example.com/login', {
username: 'admin',
password: '12345'
})
.then(res => console.log('Token:', res.data.token))
.catch(err => console.error('Login failed:', err));
PHP API Integration Example
<?php
$url = "https://jsonplaceholder.typicode.com/posts";
$data = array("title" => "API Example", "body" => "Hello World", "userId" => 1);
$options = array(
"http" => array(
"header" => "Content-Type: application/json\r\n",
"method" => "POST",
"content" => json_encode($data),
),
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
echo $result;
?>
Python API Integration Example
import requests
response = requests.get("https://jsonplaceholder.typicode.com/posts/1")
print(response.json())
POST Example:
import requests
data = {"title": "Python API", "body": "Learning integration", "userId": 10}
response = requests.post("https://jsonplaceholder.typicode.com/posts", json=data)
print(response.json())
Node.js API Integration Example
const fetch = require("node-fetch");
fetch("https://jsonplaceholder.typicode.com/users")
.then(res => res.json())
.then(data => console.log(data));
Using cURL for API Testing
curl -X GET https://jsonplaceholder.typicode.com/posts
POST Example:
curl -X POST https://jsonplaceholder.typicode.com/posts \
-H "Content-Type: application/json" \
-d '{"title":"cURL Demo","body":"API Integration via cURL","userId":1}'
API Authentication Techniques
| Type | Usage |
|---|---|
| API Key | Simple and fast; used in headers or query strings |
| Bearer Token (JWT) | Common in REST APIs; secure and time-limited |
| OAuth 2.0 | Used for third-party access (Google, Facebook) |
| Basic Auth | Uses username and password (less secure) |
Example (Bearer Token):
fetch("https://api.example.com/data", {
headers: {
"Authorization": "Bearer YOUR_ACCESS_TOKEN"
}
});
Handling JSON Data in APIs
Convert to JSON (JS):
let data = {name: "Alice", age: 22};
console.log(JSON.stringify(data));
Parse JSON:
let response = '{"status":"success"}';
let obj = JSON.parse(response);
console.log(obj.status);
Best Practices for API Integration
✅ Always use HTTPS
✅ Keep your API keys private
✅ Implement rate limiting and caching
✅ Use environment variables for secrets
✅ Log and handle errors gracefully
✅ Test your endpoints with tools like Postman or Insomnia
Common HTTP Response Codes
| Code | Meaning |
|---|---|
| 200 | OK – Request successful |
| 201 | Created – Resource created |
| 400 | Bad Request |
| 401 | Unauthorized |
| 403 | Forbidden |
| 404 | Not Found |
| 500 | Internal Server Error |
Popular Public APIs for Practice
| API Name | Purpose | Example URL |
|---|---|---|
| JSONPlaceholder | Dummy REST API for testing | https://jsonplaceholder.typicode.com |
| OpenWeatherMap | Weather data | https://api.openweathermap.org |
| TheCatAPI | Random cat images | https://api.thecatapi.com |
| CoinGecko | Crypto prices | https://api.coingecko.com |
| REST Countries | Country info | https://restcountries.com |
Internal Backlinks
FAQ — API Integration Cheatsheet
Q1: What does API stand for?
API means Application Programming Interface — a bridge that allows apps to communicate.
Q2: What’s the difference between REST and SOAP APIs?
REST uses lightweight JSON and HTTP; SOAP uses XML and heavier protocols.
Q3: How do I test my API calls?
Use tools like Postman, Insomnia, or browser DevTools → Network tab.
Q4: Is API integration difficult?
Not at all! With Fetch or Axios, you can integrate APIs easily using just a few lines of code.
Q5: What is an API key?
An API key is a unique identifier used for authenticating requests to an API.

