xxxxxxxxxx
import requests
import json
r = requests.get("URL")
j=r.json()
print(j)
xxxxxxxxxx
import requests
# Define the API endpoint URL
url = 'https://api.example.com/data'
try:
# Make the API request
response = requests.get(url)
# Check if the request was successful (status code 200)
if response.status_code == 200:
# Extract the data from the response
data = response.json()
# Process the data as needed
# ...
else:
print('Error:', response.status_code)
except requests.exceptions.RequestException as e:
print('Error:', e)
xxxxxxxxxx
from flask import Flask
app = Flask(__name__)
@app.route('/api', methods=['GET'])
def hello_world():
return 'Hello, this is my API!'
if __name__ == '__main__':
app.run()
xxxxxxxxxx
from flask import Flask, jsonify
app = Flask(__name__)
@app.route('/hello', methods=['GET'])
def hello():
return jsonify(message='Hello, World!')
if __name__ == '__main__':
app.run()
xxxxxxxxxx
response = requests.get("https://api.open-notify.org/this-api-doesnt-exist")
xxxxxxxxxx
from flask import Flask, jsonify, request
app = Flask(__name__)
# Example route
@app.route('/api', methods=['GET'])
def api():
# Perform actions
data = {
'message': 'Hello, API!'
}
return jsonify(data)
if __name__ == '__main__':
app.run()