Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local url = "https://your-api.com/endpoint" -- Replace with your actual API URL
- local bearer_token = "your_bearer_token_here" -- Replace with your actual token
- -- Find an attached monitor
- local monitor = peripheral.find("monitor")
- if not monitor then
- print("No monitor found!")
- return
- end
- monitor.setTextScale(1) -- Adjust text scale for readability
- monitor.clear()
- monitor.setCursorPos(1, 1) -- Reset cursor to the top-left
- -- Define request headers
- local headers = {
- ["Authorization"] = "Bearer " .. bearer_token,
- ["Accept"] = "application/json"
- }
- -- Perform HTTP request
- local response = http.get(url, headers)
- if response then
- local body = response.readAll() -- Read response body
- response.close() -- Close response to free memory
- print("Response: " .. body) -- Print in computer terminal
- -- Display response on monitor
- monitor.write("API Response:")
- monitor.setCursorPos(1, 2) -- Move to next line
- monitor.write(body) -- Display API response
- else
- print("HTTP request failed")
- monitor.write("HTTP request failed")
- end
Advertisement
Add Comment
Please, Sign In to add comment