api-explorer
is a web project that demonstrates how to use different methods to fetch data from APIs. It utilizes three different approaches—XMLHttpRequest, Fetch API, and Axios—to retrieve and display data. The project fetches user and post data from the JSONPlaceholder API and displays it in a user-friendly format.
- Display Users and Posts: Fetch and display users and posts from the JSONPlaceholder API.
- Dynamic Content Loading: Load user details and posts dynamically based on user selection.
- Different Data Fetching Methods: Demonstrates data fetching using XMLHttpRequest, Fetch API, and Axios.
index.html
: Contains the main structure of the web page, including theusers
andposts
sections.index.js
: Contains the JavaScript logic for fetching and displaying data from the API.style.css
: Contains the styling for the project.
-
Clone the Repository:
git clone https://github.com/your-username/api-explorer.git
-
Navigate to the Project Directory:
cd api-explorer
-
Install Dependencies: Make sure you have Axios installed. You can install it using npm:
npm install axios
-
Open the Project: Open
index.html
in your web browser to see the project in action.
fill(elements, type)
: Populates theusers
orposts
sections based on thetype
parameter.getDataByXMLHR(url, callback)
: Fetches data using XMLHttpRequest and calls the provided callback function.getDataByFetch(url, callback)
: Fetches data using the Fetch API and calls the provided callback function.getDataByAxios(url, callback)
: Fetches data using Axios and calls the provided callback function.showPost(user, element)
: Displays posts for the selected user and highlights the selected user.
#main
: Main container with gradient background and flex layout.#users
: Section for displaying user information.#posts
: Section for displaying posts..user
and.post
: Styling for user and post elements including background color, padding, and border..user.selected
: Highlighted style for the selected user.
Feel free to fork the repository and make your own contributions. Open issues and pull requests are welcome.
This project is licensed under the MIT License. See the LICENSE file for more details.