Skip to content
Snippets Groups Projects
Commit c79c8ad2 authored by Rolf Niepraschk's avatar Rolf Niepraschk
Browse files

"http-requests"

parent 71d0a95f
Branches
No related tags found
No related merge requests found
......@@ -5,7 +5,7 @@
import socket, signal, sys, time
import json
DEVHUB_URL = 'http://localhost:9009/'
DEVHUB_URL = 'http://e75491:9009/'
HTTP_HEADER = 'Content-Type: application/json'
DATA_TEMPLATE = { 'Action':'TCP', 'Host':CONTROLER_HOST }
......
#!/usr/bin/env python3
# See: https://www.datacamp.com/tutorial/making-http-requests-in-python
import requests
# Free fake API for testing and prototyping.
# The API endpoint
url = "https://jsonplaceholder.typicode.com/posts/1"
# A GET request to the API
response = requests.get(url)
# Print status code from original response (not JSON)
print(response.status_code)
# Print the response
response_json = response.json()
print(response_json)
"""
{'userId': 1, 'id': 1, 'title': 'sunt aut facere repellat provident occaecati excepturi optio reprehenderit', 'body': 'quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto'}
"""
#!/usr/bin/env python3
# See: https://www.datacamp.com/tutorial/making-http-requests-in-python
import requests
# Define new data to create
new_data = {
"userID": 1,
"id": 1,
"title": "Making a POST request",
"body": "This is the data we created."
}
# The API endpoint to communicate with
url_post = "https://jsonplaceholder.typicode.com/posts"
# A POST request to tthe API
post_response = requests.post(url_post, json=new_data)
# Print status code from original response (not JSON)
print(post_response.status_code)
# Print the response
post_response_json = post_response.json()
print(post_response_json)
"""
{'userID': 1, 'id': 101, 'title': 'Making a POST request', 'body': 'This is the data we created.'}
"""
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment