FoodWaste API는 음식물쓰레기 무게를 측정하여 관련 인적사항을 저장하고 조회할 수 있는 API입니다.
URL: https://www.nz-hero.com/api/foodwaste
Method: POST
Description: 새로운 음식물쓰레기 데이터를 생성합니다.
Content-Type: application/json
Request Body:
{
"timestamp": "2024-05-17T12:34:56", // optional, default is current time
"weight": 2.5,
"region": "Seoul",
"school": "High School ABC",
"grade": "10",
"class_name": "A",
"student_number": "23",
"gender": "Male"
}
Content-Type: application/json
Response Body:
{
"message": "New food waste entry created successfully!"
}
URL: https://www.nz-hero.com/api/foodwaste
Method: GET
Description: 최대 10개의 최신 음식물쓰레기 데이터를 조회합니다.
Query Parameters:
limit
(optional): 조회할 데이터의 개수. 기본값은 10.
Content-Type: application/json
Response Body:
[
{
"timestamp": "2024-05-17T12:34:56",
"weight": 2.5,
"region": "Seoul",
"school": "High School ABC",
"grade": "10",
"class_name": "A",
"student_number": "23",
"gender": "Male"
},
...
]
import requests
import json
# POST request to create a new FoodWaste entry
post_url = "https://www.nz-hero.com/api/foodwaste"
post_data = {
"timestamp": "2024-05-17T12:34:56",
"weight": 2.5,
"region": "Seoul",
"school": "High School ABC",
"grade": "10",
"class_name": "A",
"student_number": "23",
"gender": "Male"
}
post_headers = {
"Content-Type": "application/json"
}
post_response = requests.post(post_url, data=json.dumps(post_data), headers=post_headers)
print(post_response.json())
# GET request to retrieve the latest FoodWaste entries
get_url = "https://www.nz-hero.com/api/foodwaste"
get_params = {
"limit": 10
}
get_response = requests.get(get_url, params=get_params)
print(get_response.json())
# POST request
curl -X POST https://www.nz-hero.com/api/foodwaste -H "Content-Type: application/json" -d '{
"timestamp": "2024-05-17T12:34:56",
"weight": 2.5,
"region": "Seoul",
"school": "High School ABC",
"grade": "10",
"class_name": "A",
"student_number": "23",
"gender": "Male"
}'
# GET request
curl -X GET "https://www.nz-hero.com/api/foodwaste?limit=10"