0% found this document useful (0 votes)
195 views

Cloud Computing and Web Services Journal

This document discusses several practical examples related to cloud computing and web services. It covers creating simple REST and SOAP services using Node.js and Express, consuming APIs, installing KVM virtualization, and uploading/downloading files using Multer.

Uploaded by

Saket Malik
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
195 views

Cloud Computing and Web Services Journal

This document discusses several practical examples related to cloud computing and web services. It covers creating simple REST and SOAP services using Node.js and Express, consuming APIs, installing KVM virtualization, and uploading/downloading files using Multer.

Uploaded by

Saket Malik
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 28

TYCS Sem VI Cloud Computing and Web Services

Practical 1
Aim: define a simple service to convert rs into dollar and call it from
different platforms like java and .net:
Program:

Const express = require('express');


Const axios = require('axios');

Const app = express();

Const exchangerateapi = 'https://api.exchangerate-api.com/v4/latest/inr';

App.get('/convert', async (req, res) => {


const { amount, to } = req.query;

try {
const response = await axios.get(exchangerateapi);
const exchangerate = response.data.rates[to];

if (!exchangerate) {
return res.status(400).json({ error: 'invalid currency code' });
}

const convertedamount = (amount * exchangerate).tofixed(2);


res.json({ convertedamount });
} catch (error) {
console.error(error);
res.status(500).json({ error: 'an error occurred while converting currency' });
}
});

Const port = process.env.port || 3000;


App.listen(port, () => {
console.log(`server listening on port ${port}`);
});

Go to desktop>cmd> type node filename.js (node app.js)


Copy port no (3000)

1
TYCS Sem VI Cloud Computing and Web Services

Go to browser type--- localhost:3000/convert?amount=100000&to=usd

Output:

2
TYCS Sem VI Cloud Computing and Web Services

Practical 2
Aim: create a simple soap service
Program: (simple soap service using node.js)

Const express = require("express");

Var app = express();

App.get("/add/:num_1/:num_2", function(req, res) {


const num1 = req.params.num_1;
const num2 = req.params.num_2;
const result = parseint(num1) + parseint(num2);
res.json({result: result});
})

App.get("/sub/:num_1/:num_2", function(req, res) {


const num1 = req.params.num_1;
const num2 = req.params.num_2;
const result = parseint(num1) - parseint(num2);
res.json({result: result});
})

App.get("/mult/:num_1/:num_2", function(req, res) {


const num1 = req.params.num_1;
const num2 = req.params.num_2;
const result = parseint(num1) * parseint(num2);
res.json({result: result});

3
TYCS Sem VI Cloud Computing and Web Services

})

App.get("/div/:num_1/:num_2", function(req, res) {


const num1 = req.params.num_1;
const num2 = req.params.num_2;
const result = parseint(num1) / parseint(num2);
res.json({result: result});
})

App.listen(3300, function() {
console.log("the port is 3300");
});

Run in vs code copy the local host port number

Open google chrome type--

4
TYCS Sem VI Cloud Computing and Web Services

http://localhost:3300/add/2/3
http://localhost:3300/sub/2/3
http://localhost:3300/mult/2/3
http://localhost:3300/div/2/3

Output:

5
TYCS Sem VI Cloud Computing and Web Services

Practical 3
Aim: create a simple rest service

Program:
Open google crome >search spring boot initializer

Select>project:maven
language:java
spring boot :3.2.3
fill up project metadata

6
TYCS Sem VI Cloud Computing and Web Services

Go to dependencies >search web

Add dependencies

7
TYCS Sem VI Cloud Computing and Web Services

Click on generate button (below) to download spring boot project as zip


file
extract the zip file
Open eclipse>go to file>import

Select existing maven project

8
TYCS Sem VI Cloud Computing and Web Services

Browse springboot-firat-app >click on finish

Select springboot-first-app>src>main>java>com>springboot>app

9
TYCS Sem VI Cloud Computing and Web Services

Right click on app>new>others>select class>next

10
TYCS Sem VI Cloud Computing and Web Services

Write code in welcomecontroller.java file

Now go to springbootfirstappapplication.java

11
TYCS Sem VI Cloud Computing and Web Services

Run the program (as java application)

Go to browser type>localhost:8080/welcome

Output:

12
TYCS Sem VI Cloud Computing and Web Services

Practical 4
Aim : develop an application to consume google’s search / google’s map
restful web service

Program:

Import requests

Def get_geolocation(api_key, search_string):


base_url = "https://us1.locationiq.com/v1/search"
params = {
'key': api_key,
'q': search_string,
'format': 'json',
}

response = requests.get(base_url, params=params)


data = response.json()

if response.status_code == 200 and data:


result = {
'place_id': data[0].get('place_id', ''),
'lat': data[0].get('lat', ''),
'lon': data[0].get('lon', ''),
'display_name': data[0].get('display_name', ''),
}
return result
else:

13
TYCS Sem VI Cloud Computing and Web Services

print(f"error: {response.status_code} - {data.get('error', 'no error


message')}")
return none

Api_key = 'pk.71c93f03731ac10faf75d7e071df51c1 '


Search_string = input("enter the location : ")

Result = get_geolocation(api_key, search_string)

If result:
print("output:")
for key, value in result.items():
print(f"{key}: {value}")

Browse location iq>signup with email> click on the link provided by location iq
(on your email)>you will get your access token copy the key and paste in the
python code:

Run the code


Output:

14
TYCS Sem VI Cloud Computing and Web Services

15
TYCS Sem VI Cloud Computing and Web Services

Practical 5
Aim : installation and configuration of virtualization using kvm
Program:
Commands:
1.sudo grep-c"svm\|vmx"/proc/cpuinfo
2.sudo apt install qemu-kvm libvirt-daemon-system virt-manager brid
3.sudo apt-get update
4.sudo apt-get install qemu-kvm libvirt-daemon-system virt-manager bridge-
utils
5.sudo apt install qemu-kvm libvirt-clients libvirt-daemon-system bridge-utils
6.sudo systemctl start libvirtd
7.sudo usermod -ag kvm $user
8.sudo systemctl is-active libvirtd
9.sudo usermod -ag libvirt $user
Sudo usermod -ag kvm $user
10.virt-manager
11.kvm-ok

Output:

16
TYCS Sem VI Cloud Computing and Web Services

17
TYCS Sem VI Cloud Computing and Web Services

Practical 6

Aim : develop an application to download image/video from server or


upload image/video to server using mtom techniques

Program:

(node.js) code:

Const express = require('express');

Const multer = require('multer');

Const path = require('path');

Const fs = require('fs');

Const app = express();

Const port = 3000;

// define storage using multer.diskstorage

Const storage = multer.diskstorage({

destination: (req, file, cb) => {

// set the destination folder where the file will be saved

const uploadfolder = 'uploads';

fs.mkdirsync(uploadfolder, { recursive: true });

cb(null, uploadfolder);

},

filename: (req, file, cb) => {

// set the filename to the original filename

cb(null, file.originalname);

},

});

18
TYCS Sem VI Cloud Computing and Web Services

Const upload = multer({ storage: storage });

App.post('/upload', upload.single('file'), (req, res) => {

const file = req.file;

// check if file is present

if (!file) {

return res.status(400).json({ success: false, message: 'no file uploaded.' });

// process the file as needed (save to disk, database, etc.)

res.json({ success: true, message: 'file uploaded successfully.' });

});

App.get('/download/:filename', (req, res) => {

const filename = req.params.filename;

const filepath = path.join(__dirname, 'uploads', filename);

// check if file exists

if (fs.existssync(filepath)) {

// implement logic to send the file as a response

res.sendfile(filepath);

} else {

res.status(404).json({ success: false, message: 'file not found.' });

});

App.listen(port, () => {

19
TYCS Sem VI Cloud Computing and Web Services

console.log(server is running on http://localhost:${port});

});

run the code: it will start the server at localhost:3000

Open postman open a new page & choose post method

Enter the url of the server: http://localhost:3000/upload

Then click on body>form data>name the key item and file type: file

20
TYCS Sem VI Cloud Computing and Web Services

In value tab enter the file you want to upload to the server

Click on send

Upload output:

Download:

21
TYCS Sem VI Cloud Computing and Web Services

choose get method

Enter the url of the server: http://localhost:3000/download/kitten.jpg

Click on submit

22
TYCS Sem VI Cloud Computing and Web Services

Download output :

23
TYCS Sem VI Cloud Computing and Web Services

Practical 7
Aim : cloud functionality vsi (virtual server infrastructure) infrastructure
as a service (iaas), storage
Program:

After installation, it will show you an ip address. Put it im your browser to


access your administrator page the default user credentials are user: admin
and password: adimin. For root login - username- root and password -
password.

24
TYCS Sem VI Cloud Computing and Web Services

The first screen after login shows many options to install and deploy any
virtual machine. To install a virtual machine click on virtuai machine-> upload
iso file option and upload the bootable iso file. Here, we are going to upload
linux elementary 0s is0.

Once you uploaded the file, create vimtemplate. In this option you are basically
configuring your virtual machine's storage location, cpu, memory, node etc.

25
TYCS Sem VI Cloud Computing and Web Services

Here, you will find single nodes ana vw po01 1 respective options because
everything was installed at the single server.

Now, click on vmtemplates and you will see a template which you have created
in step 4. To start your machine go to run action tab and click on the green
arrow. Under status tab, it shows the running text with the green circle which
shows that your machine is running without any errors. To view your virtual
machine click on a blue square box under action tab.

To view your virtual machine you have to download spice client tool. The
download link can be found under the links option. After downloading the
application, click on the blue square to view machine. When you click on it, the
browser will pop-up for launching the application.

26
TYCS Sem VI Cloud Computing and Web Services

If the application does not launch automatically, launch it manually by entering


the link and password in the remote viewer tool which you will see in the pop-
up message.

Once it connects, enter the password which was given in the link and click ok.

Finally you will able to view and control your virtual machine.

27
TYCS Sem VI Cloud Computing and Web Services

28

You might also like