waffle_counter_backend/client_example.py

30 lines
718 B
Python
Raw Normal View History

2024-03-27 03:33:19 +01:00
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import requests
import json
# Define the API endpoint URL
api_url = 'http://localhost:8042/buzzed' # Update with your actual API URL
# Data payload to be sent as JSON
data_payload = {
'buzzer': 'buzzer1',
'waffle_ready': 1
}
# Convert the payload to JSON format
json_payload = json.dumps(data_payload)
# Set the headers to indicate JSON content
headers = {'Content-Type': 'application/json'}
# Send POST request to the API endpoint
response = requests.post(api_url, data=json_payload, headers=headers)
# Check the response status
if response.status_code == 200:
print('Data added successfully!')
else:
print(f'Error adding data: {response.text}')