CloudComputing_Practical1
CloudComputing_Practical1
Define a simple services like Converting Rs into Dollar and Call it from different platform
like JAVA and .NET
Downloads Required:
After Downloading Node.js, JDK and Dotnet SDK, Set the Path in Environment Variable in
User Variables > Path > Edit > New and Paste the Path for Node.js, JDK and Dotnet SDK
Demonstration:
Now check the versions that shows path is set for Nodejs, Java JDK and Dotnet SDK
Here all versions are shown so path is set by checking versions for Nodejs, Java JDK and
Dotnet SDK.
1. Design the Currency Conversion Service:
Create a simple API that takes an amount in Indian Rupees and returns the equivalent
amount in US Dollars. You can use a simple formula for conversion, or you can fetch real-
time exchange rates from a reliable source.
POST/convert
Request:
Response:
You can implement the service using any programming language and framework. For
simplicity, let's use Node.js with Express in this example,
Inside currency-conversion-service > this is the folder architecture after initializing npm and
express body-parser.
Filename: server.js
Code:
const express = require('express');
app.use(bodyParser.json());
// Perform the conversion (use a real exchange rate or a fixed rate for simplicity)
});
app.listen(port, () => {
});
Output:
Click View > Terminal:
PS C:\Users\Kishore\Documents\Cloud_Computing_Practical1\currency-conversion-service> node
server.js
Response:
Demonstration:
File Architecture:
Filename: JavaClient.java
Code:
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.http.HttpRequest.BodyPublishers;
import java.net.http.HttpResponse.BodyHandlers;
.uri(URI.create(uri))
.header("Content-Type", "application/json")
.POST(BodyPublishers.ofString(requestBody))
.build();
client.sendAsync(request, BodyHandlers.ofString())
.thenApply(HttpResponse::body)
.thenAccept(System.out::println)
.join();
Output:
Click View > Terminal:
{"amount_in_usd":14.5}
The Output is Successful that we called the server.js with making HTTP request
Demonstration:
The java command is used to run the compiled Java bytecode. It starts the JVM, loads the
specified .class file, and then executes the main method of that class.
1. Ensure you have a .class file: This file is generated by compiling a .java file using the javac
command.
2. Run the Java program: Use the java command followed by the name of the class (without
the .class extension) to execute the program.
C#
C# Snippet
C# Dev Kit
C# Extensions
File Architecture:
Demonstration:
After entering dotnet new console command the file architecture will generate the .NET Project with
Program.cs file shown below.
Filename: Program.cs
Code:
using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
class Program
{
static async Task Main()
{
try
{
var client = new HttpClient();
var apiUrl = "http://localhost:3000/convert";
// Send an HTTP POST request to the API with the request body
var response = await client.PostAsync(apiUrl, new StringContent(jsonRequestBody,
Encoding.UTF8, "application/json"));
Output:
Click View > Terminal:
The Output is Successful that we called the server.js with making HTTP request
Demonstration:
Conclusion: The Practical worked successfully after creating currency conversion in postman with
javascript and calling with Java and .NET by HTTP Requests.