This project is a simple API Integration assignment built using Node.js + Express. It fetches data from two public REST API endpoints, caches the response locally, and exposes clean API routes with filtering and detailed views.
This fulfills the requirements of the GLOBAL TREND – API Integration Internship Assignment.
-
Fetch data from JSONPlaceholder (Posts + Users)
-
Cache responses locally (
cache.json) -
API endpoints for:
- Listing with filtering
- Viewing details by ID
-
Error handling for:
- Network failure
- Timeout
- Malformed responses
-
Simple, readable code structure
- Node.js
- Express.js
- Axios
- File System (fs) for caching
project/
│── src/
│ ├── server.js # Entry point
│ ├── apiClient.js # Fetch + error handling
│ └── routes.js # Express routes
│── cache.json # Cached API data
│── package.json
└── README.md
npm install
npm start
Server runs at:
http://localhost:3000
GET /api/posts
Optional Filters
GET /api/posts?userId=1
GET /api/posts?title=qui
GET /api/posts/:id
Example:
GET /api/posts/5
GET /api/users
GET /api/users/:id
GET /api/refresh
-
When
/postsor/usersis requested:- If cache exists → return cached data
- Else → fetch from API, save to
cache.json, then return
-
When
/refreshis called:- Always fetch fresh data
- Overwrite old cache
This reduces API calls and speeds up responses.
- Network failure fallback to cache
- Timeout handling for Axios
- Invalid/malformed API response
- Missing cache file scenario
https://jsonplaceholder.typicode.com/postshttps://jsonplaceholder.typicode.com/users
- Caching is file-based for simplicity
- Only GET routes needed as per assignment
- No database required