Cloud Computing Practical3
Cloud Computing Practical3
Downloads Required:
After Downloading Python, Set the Path in Environment Variable in User Variables > Path >
Edit > New and Paste the Path for Python.
New version is 3.13, Here the version is 3.12 so following the same for new version.
Demonstration:
Check Version:
Python Programming Language
Step 1: Install Flask: Make sure you have Python installed on your system.
Open cmd and type the following command
Step 2: Create a folder name SimpleRESTService, Open with VS Code and create python
file.
Extensions:
Python
Python Debugger
Filename: app.py
Code:
from flask import Flask, jsonify, request
app = Flask(__name__)
# Sample data
data = [
{'id': 1, 'name': 'Item 1'},
{'id': 2, 'name': 'Item 2'},
]
Output:
View>Terminal
Type
Path> python app.py
Demonstration:
Postman
API Testing Software Application to Test the API
Open Postman
# Endpoint to get all items
Send a GET Request:
URL: http://127.0.0.1:5000/items
Response:
{
"items": [
"id": 1,
},
"id": 2,
Demonstration:
# Endpoint to get a specific item by ID
Send a GET Request:
URL: http://127.0.0.1:5000/items/1
Response:
{
"item": {
"id": 1,
"name": "Item 1"
}
}
Provides specific id from Sample Data available i.e., URL: http://127.0.0.1:5000/items/1
Demonstration:
Throws Error when not item not found from Sample Data. Example
URL: http://127.0.0.1:5000/items/100
Demonstration:
{"name":"item3"}
Response:
"item": {
"id": 3,
"name": "item3"
},
Demonstration:
---------------------------------