# Hands-On Project: Simple Integration Task

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1726936077296/6b5d80fb-1ff7-4b04-8230-c2e244cbec76.jpeg)

Photo by [Wolfgang Hasselmann](https://unsplash.com/@wolfgang_hasselmann?utm_source=medium&utm_medium=referral) on [Unsplash](https://unsplash.com?utm_source=medium&utm_medium=referral)

Welcome to Day 5! Today, we’re going to get hands-on with a simple integration task using a GET request to fetch data from an API. This project will help you understand the basics of integrating APIs into your web applications.

#### Project Description

For this project, we’ll integrate a weather API into a web application. This will involve making a GET request to fetch weather data based on a city name input by the user. I chose this project because it’s a common use case that highlights essential skills like handling API requests and displaying dynamic data.

#### Step-by-Step Instructions

**1\. Setting Up the Development Environment:**

*   Use **Visual Studio Code (VS Code)** as our IDE.
*   Ensure you have basic knowledge of HTML, CSS, and JavaScript.

**2\. Obtaining API Keys:**

*   Sign up on a weather API service like OpenWeatherMap.
*   Obtain your API key from the API provider.

**3\. Writing the Code:**

*   **HTML**: Create a simple form to input the city name.
*   **CSS**: Add basic styling to make the application look clean.
*   **JavaScript**: Write the script to fetch data from the API and display it on the webpage.

Here’s a simple example:

<!DOCTYPE html\>  
<html lang\="en"\>  
<head\>  
    <meta charset\="UTF-8"\>  
    <meta name\="viewport" content\="width=device-width, initial-scale=1.0"\>  
    <title\>Weather App</title\>  
    <style\> body {  
            font-family: Arial, sans-serif;  
            display: flex;  
            justify-content: center;  
            align-items: center;  
            height: 100vh;  
            flex-direction: column;  
        }  
        input, button {  
            padding: 10px;  
            margin: 5px;  
        } </style\>  
</head\>  
<body\>  
    <h1\>Weather App</h1\>  
    <input type\="text" id\="city" placeholder\="Enter city name"\>  
    <button onclick\="getWeather()"\>Get Weather</button\>  
    <div id\="result"\></div\>  
  
    <script\> async function getWeather() {  
            const city = document.getElementById('city').value;  
            const apiKey = 'YOUR\_API\_KEY';  
            const url = \`https://api.openweathermap.org/data/2.5/weather?q=${city}&appid=${apiKey}\`;  
              
            try {  
                const response = await fetch(url);  
                const data = await response.json();  
                  
                if (data.cod === 200) {  
                    document.getElementById('result').innerHTML = \`  
                        <h2>${data.name}</h2>  
                        <p>Temperature: ${(data.main.temp - 273.15).toFixed(2)} °C</p>  
                        <p>Weather: ${data.weather\[0\].description}</p>  
                    \`;  
                } else {  
                    document.getElementById('result').innerHTML = \`<p>${data.message}</p>\`;  
                }  
            } catch (error) {  
                document.getElementById('result').innerHTML = \`<p>Error fetching data</p>\`;  
            }  
        } </script\>  
</body\>  
</html\>

**Testing and Debugging:**

*   Use **Postman** to test the API endpoints and ensure they return the expected data.
*   Debug any issues by checking the console logs and error messages.

#### Tools Used

*   **VS Code**: For writing and editing code.
*   **Postman**: For testing API requests.
*   **GitHub**: For version control and collaboration (if working in a team).

#### Expected Outcome

The final application will allow users to enter a city name and fetch the current weather information for that city. It will display the city name, temperature, and weather description.

**Visual Example:**

#### Tips and Best Practices

*   **API Key Security**: Never expose your API keys in the frontend code. Use environment variables or server-side code to manage them securely.
*   **Error Handling**: Always include error handling to manage unexpected API responses or network issues.
*   **Keep it Simple**: Start with a basic implementation and gradually add more features.

#### Engagement

What other simple integration projects have you worked on? What challenges did you face, and how did you overcome them? Share your experiences in the comments below!

#SoftwareIntegration #APIIntegration #WeatherApp #WebDevelopment #GETRequest #CodingProject
