Rest API | Web Service Tutorial

Rest API | Web Service Tutorial

Telusko

5 лет назад

1,200,282 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@mohamedasif690
@mohamedasif690 - 08.02.2023 14:21

I'm using jersey v2.29

I'm getting 500 error when return java object as XML... but no any error on console.. But i can get string if return string

Ответить
@sahilsamaiya6579
@sahilsamaiya6579 - 10.03.2023 15:05

what are the prerequisites for restful service in java

Ответить
@vijaykamble4051
@vijaykamble4051 - 18.03.2023 21:13

i am getting error 404 --the origin server did not find a current representation for the target resource or is not willing to disclose that one exists

Ответить
@nehasabnani-my3si
@nehasabnani-my3si - 22.03.2023 21:24

Thank you sir for this tutorial

Ответить
@omit_krish
@omit_krish - 31.03.2023 05:52

While running time showing (java.lang.ClassNotFoundException:jakarta.servlet.filter) but I have added related dependencies also still not solving the problem...

Ответить
@Through_MyEye
@Through_MyEye - 01.04.2023 13:59

i dont understand that why he have to talk about servlet in everything instead of the topic of the tutorial,.I was referring spring boot there also he lecture about servlet n all , then i switched to this here also the same thing, everybody here is not from software background here, Please understand this, I have learnt java only with the help of telusko, but while learning advance , its disturbing that he talks more about the topics which everybody might not understand

Ответить
@PrinceJeniFX
@PrinceJeniFX - 11.04.2023 01:23

Please Which app do you use for your screen recording?

Ответить
@JustinWrona
@JustinWrona - 19.04.2023 19:35

this is so cringe-worthy

Ответить
@nitishchowdary123
@nitishchowdary123 - 27.04.2023 10:54

Can you provide tutorials in Telugu step by step ...from spring framework

Ответить
@bagthavachalanucavasu
@bagthavachalanucavasu - 24.06.2023 15:19

that is tricky . thanks for successfully video

Ответить
@abhijeetjha3822
@abhijeetjha3822 - 28.06.2023 12:54

nice content

Ответить
@abhijeetjha3822
@abhijeetjha3822 - 28.06.2023 12:59

nice comment

Ответить
@muralikrishnasiju
@muralikrishnasiju - 06.07.2023 13:13

"because I love Jason"🙃

Ответить
@VickyGupta-lt5ub
@VickyGupta-lt5ub - 14.08.2023 13:34

@RestController
@RequestMapping(value = "/employee")
public class EmployeeController {

@Autowired
private EmployeeRep employeeRep;

@GetMapping("/one")
public Map<String, Long> maleAndFemaleEmployees() {
List<Employee> noOfMaleAndFemaleEmployees = employeeRep.findAll();

Map<String, Long> collect = noOfMaleAndFemaleEmployees.stream()
.collect(Collectors.groupingBy(Employee::getGender, Collectors.counting()));
return collect;

}

@GetMapping("/two")
public Stream<String> findAllEmpDeptDistinct() {
List<Employee> findAll = employeeRep.findAll();

Stream<String> distinct = findAll.stream().map(app -> app.getDept()).distinct();

return distinct;

}

@GetMapping("/three")
public Map<String, Double> avgAgeOfMaleAndFemale() {
List<Employee> avgAgeOfMaleAndFemaleEmployees = employeeRep.findAll();

Map<String, Double> collect = avgAgeOfMaleAndFemaleEmployees.stream()
.collect(Collectors.groupingBy(Employee::getGender, Collectors.averagingDouble(Employee::getAge)));
return collect;

}

@GetMapping("/four")
public Optional<Employee> highPaidEmployee() {
List<Employee> highestPaidDetailFull = employeeRep.findAll();

Optional<Employee> max = highestPaidDetailFull.stream()
.collect(Collectors.maxBy(Comparator.comparingDouble(Employee::getSalary)));
return max;
}

@GetMapping("/five")
public ResponseEntity<String> highestPaidEmployee() {
List<Employee> highestPaid = employeeRep.findAll();

Optional<Employee> max = highestPaid.stream().max(Comparator.comparing(Employee::getSalary));

if (max.isPresent()) {
Employee employee = max.get();
String name = employee.getName();
String department = employee.getDept();

String response = "Highest Paid Employee: " + name + " (Department: " + department + ")";
return ResponseEntity.ok(response);
} else {
return ResponseEntity.notFound().build();
}
}

@GetMapping("/six")
public Stream<String> joinedafter2015() {
List<Employee> findAll = employeeRep.findAll();

Stream<String> map = findAll.stream().filter(te -> te.getYearOfJoining() > 2015).map(Employee::getName);
return map;
}

@GetMapping("/seven")
public Map<String, Long> employeeCountByDepartment() {
List<Employee> countByDepartment = employeeRep.findAll();

Map<String, Long> collect = countByDepartment.stream()
.collect(Collectors.groupingBy(Employee::getDept, Collectors.counting()));

return collect;

}

@GetMapping("/eight")
public Map<String, Double> avgSalaryOfDepartments() {
List<Employee> avgSalaryOfDepts = employeeRep.findAll();

Map<String, Double> collect = avgSalaryOfDepts.stream()
.collect(Collectors.groupingBy(Employee::getDept, Collectors.averagingDouble(Employee::getSalary)));

return collect;

}

@GetMapping("/nine")
public Optional<Employee> youngestMaleEmployeeInProductDevelopment() {
List<Employee> youngestMaleEmployeeInProductDeve = employeeRep.findAll();

Optional<Employee> max = youngestMaleEmployeeInProductDeve.stream()
.filter(te -> te.getGender().equals("Male") && te.getDept().equals("Product Development"))
.min(Comparator.comparing(Employee::getAge));

return max;

}

@GetMapping("/ten")
public Optional<Employee> seniorMostEmployee() {
List<Employee> seniorEmployee = employeeRep.findAll();

Optional<Employee> collect = seniorEmployee.stream()
.collect(Collectors.minBy(Comparator.comparing(Employee::getYearOfJoining)));
return collect;

}

@GetMapping("/eleven")
public Map<String, Long> countMaleFemaleEmployeesInSalesMarketing() {
List<Employee> countMaleFemaleEmpInSalesMarketing = employeeRep.findAll();

Map<String, Long> collect = countMaleFemaleEmpInSalesMarketing.stream()
.filter(te -> te.getDept().equals("Sales And Marketing"))
.collect(Collectors.groupingBy(Employee::getGender, Collectors.counting()));
return collect;

}

@GetMapping("/twelve")
public Map<String, Double> avgSalaryOfMaleAndFemaleEmployees() {
List<Employee> avgSalaryOfMaleAndFemaleEmp = employeeRep.findAll();

Map<String, Double> collect = avgSalaryOfMaleAndFemaleEmp.stream()
.collect(Collectors.groupingBy(Employee::getGender, Collectors.averagingDouble(Employee::getSalary)));
return collect;

}

@GetMapping("/thirteen")
public Map<String, List<String>> employeeListByDepartment() {
List<Employee> findAll = employeeRep.findAll();

Map<String, List<String>> collect = findAll.stream().collect(
Collectors.groupingBy(Employee::getDept, Collectors.mapping(Employee::getName, Collectors.toList())));

return collect;

}

@GetMapping("/fourteen")
public String employeeSalarySumAndAvg() {

List<Employee> empSalarySumAndAvg = employeeRep.findAll();

DoubleSummaryStatistics collect = empSalarySumAndAvg.stream()
.collect(Collectors.summarizingDouble(Employee::getSalary));

return "Total Salary = " + collect.getSum() + ", Average Salary = " + collect.getAverage();

}

@GetMapping("/fifteen")
public ResponseEntity<String> partitionEmployeesByAge() {
List<Employee> partitionEmployeesByAge25OldAnd25Young = employeeRep.findAll();

Map<Boolean, List<Employee>> collect = partitionEmployeesByAge25OldAnd25Young.stream()
.collect(Collectors.partitioningBy(te -> te.getAge() > 25));

Set<Entry<Boolean, List<Employee>>> entrySet = collect.entrySet();

String olderEmployeesResponse = "Employees older than 25 years: ";
String youngerEmployeesResponse = "Employees younger than or equal to 25 years: ";

for (Entry<Boolean, List<Employee>> entry : entrySet) {
List<Employee> list = entry.getValue();

for (Employee employee : list) {
String employeeName = employee.getName() + ", ";
if (entry.getKey()) {
olderEmployeesResponse += employeeName;
} else {
youngerEmployeesResponse += employeeName;
}
}
}

String finalResponse = olderEmployeesResponse + "\n" + youngerEmployeesResponse;

return ResponseEntity.ok(finalResponse);
}

@GetMapping("/sixteen")
public ResponseEntity<String> oldestEmployee() {

List<Employee> oldestEmp = employeeRep.findAll();
Optional<Employee> max = oldestEmp.stream().max(Comparator.comparing(Employee::getAge));

if (max.isPresent()) {
Employee employee = max.get();
String dept = employee.getDept();
int age = employee.getAge();

String response1 = "Department : " + dept;
String response2 = "Age : " + age;

String responseBody = response1 + "\n" + response2;

return ResponseEntity.ok(responseBody);
} else {
return ResponseEntity.notFound().build(); // Or any appropriate response for no employees found
}

}

@GetMapping("/seventeen")
public List<String> findAllEmpNamesStartWithA() {
List<Employee> findAll = employeeRep.findAll();

List<String> collect = findAll.stream().filter(te -> te.getName().startsWith("A")).map(Employee::getName)
.collect(Collectors.toList());

return collect;

}

@GetMapping("/eighteen")
public String findAllEmpDeptCount() {
List<Employee> findAll = employeeRep.findAll();

long count = findAll.stream().map(app -> app.getDept()).distinct().count();

return "Total Department : - " + count;

}

@GetMapping("/ninteen")
public String findAllEmpCount() {
List<Employee> allEmpCount = employeeRep.findAll();

Long count = allEmpCount.stream().collect(Collectors.counting());

return "Total Employees: " + count;

}

}

Ответить
@prashantpatidar1099
@prashantpatidar1099 - 19.08.2023 06:06

In this video details of RestAPI is just 10% and remaining 90% consist of jersey project creation, Spring project creation, jdbc etc.

Ответить
@randomByte495
@randomByte495 - 20.08.2023 12:45

Awesome explanation, seeing this in 2023

Ответить
@ASKbalrog
@ASKbalrog - 21.08.2023 01:10

Hi scuse me for my english. I tried to follow the tutorial but this error appears as soon as I invoke the rest "java.lang.NoClassDefFoundError: jakarta/servlet/Filter".
Tomcat 8 and java 1.8
The configuration is in the pom:

<properties>
<jersey.version>3.1.3</jersey.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<war.mvn.plugin.version>3.4.0</war.mvn.plugin.version>
</properties>


<dependencies>
<dependencies>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<!-- use the following artifactId if you don't need servlet 2.x compatibility -->
<!-- artifactId>jersey-container-servlet</artifactId -->
</dependency>

<dependencies>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
</dependency>


<!-- uncomment this to get JSON support
<dependencies>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-binding</artifactId>
</dependency>
-->
</dependencies>

web.xml:
<servlet>
<servlet-name>Jersey Web Application</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.telusko.demorest</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey Web Application</servlet-name>
<url-pattern>/webapi/*</url-pattern>
</servlet-mapping>

Help me Thaks

Ответить
@kunalbikramdutta2098
@kunalbikramdutta2098 - 24.09.2023 21:13

I am using tomcat10 and jersey version 3.1.3 but not able to avoid this error - SEVERE: MessageBodyWriter not found for media type=application/xml, type=class com.jersey.demorest.Alien, genericType=class com.jersey.demorest.Alien.

Ответить
@diono9
@diono9 - 05.11.2023 22:35

You helped me so much

Ответить
@HappyHappy-n6z
@HappyHappy-n6z - 23.12.2023 19:02

the XmlRootElement annotation is not working

Ответить
@HappyHappy-n6z
@HappyHappy-n6z - 23.12.2023 19:03

any help

Ответить
@abidamajeeth
@abidamajeeth - 10.01.2024 09:46

Thank you so much for your very useful videos.. Keep up the good work !

Ответить
@linstonjoyal1381
@linstonjoyal1381 - 19.02.2024 12:25

Ответить
@priyankas1665
@priyankas1665 - 20.02.2024 16:00

Sir please share video on Selenium Webdriver, TestNg,Jenkins, Maven, RestAssured

Ответить
@nishanthanr605
@nishanthanr605 - 28.02.2024 08:37

please update this video quality is bad

Ответить
@batr1868
@batr1868 - 01.03.2024 02:32

Your explanation is great, but I have a question: how can I build a front-end for a web page using this data?

Ответить
@TheThrottleGuy
@TheThrottleGuy - 01.03.2024 14:26

❤ You made this complex topic so easy. Thank you!!

Ответить
@RaviKumarOleti-h5x
@RaviKumarOleti-h5x - 05.03.2024 13:02

java.lang.ClassNotFoundException: jakarta.servlet.Filter
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1407)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1215)
at java.base/java.lang.ClassLoader.defineClass1(Native Method)
at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1017)
at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:150)
at org.apache.catalina.loader.WebappClassLoaderBase.findClassInternal(WebappClassLoaderBase.java:2478)
at org.apache.catalina.loader.WebappClassLoaderBase.findClass(WebappClassLoaderBase.java:870)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1371)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1215)
at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:538)
at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:519)
at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:149)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1070)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1010)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4957)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5264)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1396)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1386)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:145)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:919)
at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:835)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1396)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1386)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:145)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:919)
at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:263)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.StandardService.startInternal(StandardService.java:432)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:927)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.startup.Catalina.start(Catalina.java:772)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:345)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:476) I am getting this error when i try to run the application how can i eliminate this . I tried so many times but error not rectified please Solve this Error

Ответить
@sririjuldas8952
@sririjuldas8952 - 15.03.2024 05:48

What do we have to learn before learning rest API? Is having knowledge on java is enough for learning rest api

Ответить
@sanctamarina7623
@sanctamarina7623 - 16.03.2024 17:58

I get this error. Can anyone guide me how to solve this,
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

Ответить
@keshawkrishna2895
@keshawkrishna2895 - 20.04.2024 10:35

Can you please share the source code for this project

Ответить
@shuvamdash4851
@shuvamdash4851 - 30.04.2024 08:31

why my pom.xml showing error in first line

please solve it sir

Ответить
@arunelavarasan5458
@arunelavarasan5458 - 25.05.2024 21:33

Amazing! sir

Ответить
@KaustubhKolhe
@KaustubhKolhe - 13.06.2024 08:34

Jun 13, 2024 11:03:11 AM org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor aroundWriteTo
SEVERE: MessageBodyWriter not found for media type=application/xml, type=class com.RestDemo.Student, genericType=class com.RestDemo.Student.



i keep having this error just just can't fix it, i tried changing dependencies but it just dosen't work, please help

Ответить
@tsk3121
@tsk3121 - 03.07.2024 15:25

For people stuck at 41.10, copy paste below lines in pom.xml

<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.3.4</version>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>4.0.0</version>
</dependency>

Ответить
@yashwanthyerra2820
@yashwanthyerra2820 - 06.07.2024 17:39

if anyone facing an exception of class not found for sql driver
set url as follows
"jdbc:mysql://localhost:3306/{your-database-name}?useSSL=false&serverTimezone=UTC";

set usessl = false and then run it

Ответить
@BinaryBypass
@BinaryBypass - 04.08.2024 20:15

unable to find jersey in maven project help!!
🥲

Ответить
@vlogmania5129
@vlogmania5129 - 26.08.2024 18:25

Aliens Assemble!!

Ответить
@rajanchaubey1011
@rajanchaubey1011 - 29.01.2025 22:07

Hello sir can you update this project on you git repo, I searched but it is not available.

Ответить
@AnmolGarg-ss8mp
@AnmolGarg-ss8mp - 18.02.2025 08:36

sir i just want to confirm is this playlist video are good for learning today , as you can see i am 5 year late to learn about java, restapi, springboot , many updates had done in these languages, i am little bit confuse because as i do according to your videos many option are not found many error come , i don't found exact way to learn about restapi

Ответить