Giter Site home page Giter Site logo

hello_api_fast's Introduction

FastAPI Geolocation and Greeting API

This HNG project demonstrates a simple FastAPI application that retrieves a user's location (city) and temperature (based on IP address) and returns a personalized greeting message. I have hosted the API on Vercel here.

Features:

  • Uses FastAPI for a clean and efficient API framework.
  • Integrates IP Geolocation API (IP-API) to fetch location data.
  • Retrieves current weather temperature using Open-Meteo API (optional).
  • Personalizes the greeting message with a visitor name (provided as a query parameter).
  • Handles potential errors and returns informative messages.

Running the Application Locally:

Prerequisites:

  • Python 3.6+
  • uvicorn (install using pip install uvicorn)
  • httpx (install using pip install httpx)

Steps:

  1. Clone the repository (if applicable).
  2. Navigate to the project directory.
  3. Install dependencies:
pip install -r requirements.txt

Run the application:

uvicorn main:app --host 0.0.0.0 --port 8000

Access the API endpoint at http://localhost:8000/api/hello. You can optionally add a query parameter for the visitor name (e.g., http://localhost:8000/api/hello?visitor_name=John).

API Endpoint: /api/hello (GET request)

Response:

JSON
{
  "client_ip": "user's IP address",
  "location": "city name (or 'unknown')",
  "temperature": "temperature in degrees Celsius (or 'unknown')",
  "greeting": "Hello, visitor_name!, the temperature is temperature degrees Celsius in location"
}

Deployment:

The vercel.json file is configured for deployment on Vercel. Refer to Vercel's documentation for specific deployment instructions.

API Keys:

The provided APIs (IP-API and Open-Meteo) might have usage limits or require API keys for enhanced features or accuracy. Review their documentation for proper usage guidelines.

Further Enhancements:

  • Explore alternative IP geolocation and weather APIs.
  • Integrate user authentication for personalized experiences.
  • Add additional features such as weather forecasts or historical data.

hello_api_fast's People

Contributors

froschi95 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.