This is a FastAPI application providing an API to retrieve and create data about various items. The data is sourced from a JSON file and can be accessed easily!
- Python (3.7 or higher)
- pip
-
Clone the repository:
git clone https://github.com/is-it-healthy/api.git
-
Navigate to the project directory:
cd fastapi-data-api -
Create a virtual environment and activate it:
python -m venv venv source venv/bin/activate # On Windows, use 'venv\Scripts\activate'
-
Install dependencies:
pip install -r requirements.txt
Start the FastAPI application using uvicorn:
uvicorn api:app --reload( where api is the filename (api.py) )
The server will be running at http://127.0.0.1:8000.
Visit the Swagger UI for interactive documentation: http://127.0.0.1:8000/docs
-
GET /get_data/{item_id}: Retrieve information about a specific item.
-
Curl:
curl -X 'GET' \ 'http://127.0.0.1:8000/get_data/102?include_code=true&include_name=true&include_href=true&include_function=true&include_more_info=true' \ -H 'accept: application/json'
-
Request URL
http://127.0.0.1:8000/get_data/102?include_code=true&include_name=true&include_href=true&include_function=true&include_more_info=true -
Server response
{ "code": "E102", "name": "Tartrazine", "href": "e102.htm", "function": "Yellow colour, azo dye", "more_info": { "origin": "Synthetic azo dye. See for a background on azo dyes.", "characteristics": "Yellow food colour. Very soluble in water.", "products": "Many different products.", "daily_intake": "Up to 7.5 mg/kg body weight.", "side_effects": "Tartrazine is an azo dye. No side effects are known for pure tartrazine, except in people who are intolerant to salicylates (aspirin, berries, fruits); in that case tartrazine also induces intolerance symptoms. In combination with benzoates (E210-215), tartrazine is implicated in a large percentage of cases of ADHD syndrome (hyperactivity) in children. Asthmatics may also experience symptoms following consumption of tartrazine, as it is a known histamine-liberating agent.", "dietary_restrictions": "None; E102 can be consumed by all religious groups, vegans and vegetarians." } }
-
-
GET /list_items: Retrieve information about all items.
For development, it is recommended to use the --reload option with uvicorn to enable automatic code reloading:
uvicorn main:app --reloadThis project is licensed under the MIT License - see the LICENSE file for details.
