Labereco
Labereco
Step4: After creating your account, verify your email and sign in with your credentials.
Step5: Now click in profile and go to your repositories.
Step9: Launch command prompt or git bash and navigate to the created folder.
Note: you must add your name and email in git bash and the ssh keys to your Git Hub
account before performing any git operation.
Step10: Use the following command to initialize repository.
git init
Step11: Now add all the files on tracking position using following command.
git add -A
Step12: Now add commit all the files using following command.
Step13: now add the remote repo link of the GitHub to connect the folder with the GitHub
repository using the following command.
function App() {
return (
<div>
<BrowserRouter>
<NavBar />
<Routes>
<Route path="/" element={<Home />} />
<Route path="/About" element={<About />} />
<Route path="/Contact" element={<Contact />} />
</Routes>
</BrowserRouter>
</div>
);
}
About page:
Contact page:
Expriment-5
App.js
function App() {
return (
<div>
<ProductForm />
</div>
);
ProductForm.jsx
import React, { useState } from "react";
e.preventDefault();
console.log("Description:", description);
console.log("Price:", price);
};
return (
<form onSubmit={handleSubmit}>
<h1>Product Catalogue</h1>
<p>
<label>
<input
type="text"
value={ProductName}
required
/>
</label>
</p>
<p>
<label>
<textarea
value={Description}
required
/>
</label>
</p>
<p>
<label>
<input
type="number"
value={Price}
required
/>
</label>
</p>
Output :
Expriment-6
Create a spring application with spring initializer using dependencies like
spring web, spring data JPA.
To create a project using spring initializer:
Step1: open web browser and go to start.spring.io .
Step2: create project with following information:
1) Project- Maven
2) Language- java
3) Spring Boot- choose a version
4) Dependencies-
Spring Data JPA
Spring web
H2 database
Click “generate” and download the zip file.
package com.example.demo;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
@Entity
public class Person {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String name;
private int age;
public Long getId() {
return id;
}
package com.example.demo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping("/persons")
public class PersonController {
@Autowired
private PersonRepository personRepository;
@GetMapping
public List<Person> getAllPersons() {
return personRepository.findAll();
}
@PostMapping
public Person createPerson(@RequestBody Person person) {
return personRepository.save(person);
}
}
Step6: open the src/main/resources/application.properties file and paste the following code
—
spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=password
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
step7: run your Spring Boot application. You can do this by executing
‘DemoAppllication.java’ file
Output:
Expriment-7
How to create RESTful service using Spring Boot and install and
test with Postman
Step3 unzip the file and open in vs code or any other IDE.
Step4: create a simple REST controller BY adding a new Class, for example,
‘HelloController.java’:
package com.example.demo;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/api")
public class HelloController {
@GetMapping("/hello")
public String sayHello() {
return "Hello, welcome to the RESTful service!";
}
}
Step5: run your Spring Boot application. You can do this by executing
‘DemoApplication.java’ file
1) Install Postman:
Download and install Postman from https://www.postman.com/downloads/.
2) Open Postman:
Open postman on your device.
3) Make a request:
Set the request type to get. Set URL to http://localhost:8080/api/ hello
4) Send a Request:
Click on “Send” button to send the GET request and view the response
Expriment-8
Step4: Assign the database Name and collection name and click on Create Database.
Step5: open MONGOSH and write the commands in it.
use database_name
Step7: use the following command to create document in the collection
db.collection_name.insertOn
db.collection_name.insertMany([{key:value},{key:value}])
db.collection_name.find({“age”:18})
db.collection_name.find()
Step9: use the following command to update the existing documents in the collection.
db.collection_name.updateOne({key:value},{$set:{key:new_value}})
db.collection name.updateMany({key:value};{$set:key:new_value}})
Step10: use the following command to delete the documents in the database.
db.collection_name.deleteOne({key:value})
db.collection_name.deleteMany({key:value})
Expriment-9
step5: create a simple entity class representing your MongoDB document for example:
@Id
private String id;
private String name;
private double price;
package com.example.demo;
import org.springframework.data.mongodb.repository.MongoRepository;
public interface ProductRepository extends MongoRepository<Product, String> {
}
Step7: Create a REST controller that maps HTTP requests and includes CRUD operations:
// ProductController.java
package com.example.demo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Optional;
@RestController
@RequestMapping("/products")
public class ProductController {
@Autowired
private ProductRepository itemRepository;
@GetMapping
public List<Product> getAllItems() {
return itemRepository.findAll();
}
@GetMapping("/{id}")
public Optional<Product> getItemById(@PathVariable String id) {
return itemRepository.findById(id);
}
}
@PostMapping
public Product createItem(@RequestBody Product item) {
return itemRepository.save(item);
}
@PutMapping("/{id}")
public Product updateItem(@PathVariable String id, @RequestBody Product item) {
if (itemRepository.existsById(id)) {
item.setId(id);
return itemRepository.save(item);
}
return null; // Handle not found case
}
@DeleteMapping("/{id}")
public void deleteItem(@PathVariable String id) {
itemRepository.deleteById(id);
}
Step8: run your Spring Boot application. You can do this by executing
‘DemoApplication.java’.
Create docker container from docker image and run the docker
container.
Step4: you need to have the Docker image that you want to use. You can obtain an image
from Docker Hub or any other container registry by using the following command
Step5: after pulling the image, you can create and run a Docker container based on that
image by using this command.
docker ps