Xorbitingwind

Untitled

Feb 2nd, 2025
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. local url = "https://your-api.com/endpoint" -- Replace with your actual API URL
  2. local bearer_token = "your_bearer_token_here" -- Replace with your actual token
  3.  
  4. -- Find an attached monitor
  5. local monitor = peripheral.find("monitor")
  6.  
  7. if not monitor then
  8. print("No monitor found!")
  9. return
  10. end
  11.  
  12. monitor.setTextScale(1) -- Adjust text scale for readability
  13. monitor.clear()
  14. monitor.setCursorPos(1, 1) -- Reset cursor to the top-left
  15.  
  16. -- Define request headers
  17. local headers = {
  18. ["Authorization"] = "Bearer " .. bearer_token,
  19. ["Accept"] = "application/json"
  20. }
  21.  
  22. -- Perform HTTP request
  23. local response = http.get(url, headers)
  24.  
  25. if response then
  26. local body = response.readAll() -- Read response body
  27. response.close() -- Close response to free memory
  28.  
  29. print("Response: " .. body) -- Print in computer terminal
  30.  
  31. -- Display response on monitor
  32. monitor.write("API Response:")
  33. monitor.setCursorPos(1, 2) -- Move to next line
  34. monitor.write(body) -- Display API response
  35.  
  36. else
  37. print("HTTP request failed")
  38. monitor.write("HTTP request failed")
  39. end
  40.  
Advertisement
Add Comment
Please, Sign In to add comment