Postingan

Menampilkan postingan dengan label REST

Differences between @RequestParam and @PathVariable annotations in Spring MVC?

Gambar
The Spring MVC framework, one of the most popular frameworks for developing a web application in Java world also provides several useful annotations to extract data from the incoming request and mapping the request to the controller, e.g., @RequestMapping, @RequestParam, and @PathVariable. Even though both @RequestParam and @PathVariable is used to extract values from the HTTP request, there is a subtle difference between them, which makes them a useful question from an interview and spring certification point of view. We'll examine the subtle difference between @RequestParam and @PathVaraible in this article. As the name suggests, @RequestParam is used to get the request parameters from URL, also known as query parameters, while @PathVariable extracts values from URI. For example, if the incoming HTTP request to retrieve a book on topic "Java" is http://localhost:8080/shop/order/1001/receipts?date=12-05-2017, then you can use the @RequestParam annotation to retrieve the ...

How Spring MVC Makes Easy to Create RESTful Web Services in Java

Gambar
REST has now become a standard way to develop web services and when it comes to Java, there are many frameworks and library available e.g. JAX-RS, Restlet, Jersey, RESTEasy, Apache CFX etc, but I encourage Java developers to use Spring framework to develop RESTful web services. But, some of you might ask, why use Spring Framework to develop RESTful web services in Java? What is the advantage and why it's better than other frameworks and libraries available out there? Well, the most important reason I think to use Spring for developing RESTful web service is that you can use your Spring MVC experience to develop RESTful web services. This is one of the biggest advantage i.e. leveraging your years of experience on Spring MVC to expose your application as REST APIs. Another reason is that Spring has excellent support for developing RESTful web services . In last a couple of versions, starting from Spring version 3.0, it has provided a lot of enhancements to Spring MVC to provide firs...

Top 5 Books to learn REST and RESTful WebServices for Java Programmers

Gambar
The REST framework has now become the standard way to develop Web Services on the Internet. It's no more SOAP, who used to rule the world for the last two decades. The SOAP and XML went very well together in the past decade but it seems now REST and JSON have overtaken then and doing even better, thanks to the rise of JavaScript for both frontend and backend development. Since Java is also one of the most popular languages to develop backend services, there is a lot of demand for Java developers who know web services and can implement and expose existing SOAP-based services into REST style, light-weight web services. This is an excellent opportunity for intermediate and experienced Java developers to learn a more job-oriented skill to keep themselves marketable and many Java developer has already started learning REST and RESTful web services in Java. It's no surprise that I often receive requests via Facebook and email about some book recommendations on REST and RESTful web se...

How to send HTTP request using curl and wget command from Linux and UNIX? Example Tutorial

Gambar
You can use either curl or wget command to send HTTP requests from UNIX or Linux operating system. Both commands allow you to send GET and POST requests, which means you can also call REST web services.  I have a Java web application, which runs on Linux and exposes WebServices. I was writing a UNIX script to download In some data from that web service when I hit by the question, how do I make an HTTP call from UNIX? What is the UNIX command should I use? If you are also facing the same problem, then you have come to the right ht place. Basically, you can use two UNIX commands to make the HTTP request, wget, and curl. You can use curl and wget to send both GET and POST HTTP requests. My use case was rather simple, I just need to make a GET call to web service to download the data, but these two commands are mighty and provide many different options to interact with the web using HTTP right from the shell. Between wget and curl (also known as cURL), curl (I call it "karl") ...

How to Consume JSON from RESTful Web Service and Convert to Java Object - Spring RestTemplate Example

Gambar
So far, I have not written much about REST and RESTful web service, barring some interview questions like REST vs. SOAP, which is thankfully very much appreciated by my readers and some general suggestions about the best books to learn REST in the past. Today I am going to write something about how to consume JSON from a RESTful Web Service in Java using Spring Framework. I will also talk about how to convert the JSON to Java objects using Jackson. You will also learn about the RESTTemplate class from the Spring MVC framework, and how you can use it to create a REST client in Java in just a few lines of code. Similar to its predecessors JdbcTemplate and JmsTemplate, the RestTemplate is another useful utility class that allows you to interact with RESTful web services from a Java application built using the Spring framework. It's a feature-rich and supports almost all REST methods like the GET, POST, HEAD, PUT or DELETE, though we'll only use the GET method in this article to co...

Difference between @RestController and @Controller Annotation in Spring MVC and REST

Gambar
The @RestController annotation in Spring MVC is nothing but a combination of @Controller and @ResponseBody annotation. It was added into Spring 4.0 to make the development of RESTful Web Services in Spring framework easier. If you are familiar with the REST web services you know that the fundamental difference between a web application and a REST API is that the response from a web application is generally view (HTML + CSS + JavaScript)  because they are intended for human viewers while REST API just returns data in form of JSON or XML because most of the REST clients are programs. This difference is also obvious in the @Controller and @RestController annotation. The job of @Controller is to create a Map of the model object and find a view but @RestController simply returns the object and object data is directly written into HTTP response as JSON or XML. This can also be done with traditional @Controller and use @ResponseBody annotation but since this is the default behavior of ...

Top 5 Courses to Learn RESTful Web Services in Java with Spring for Experienced Developers

Gambar
In the last article, I have shared some courses to learn Microservice development with Spring framework and today, I'll talk about RESTful web service developments. The REST API and RESTful Web Services needs no introduction, it's everywhere now and driving a new internet revolution. Most of the software development in the webspace now also involves REST APIs. Gone are the days where the only interface for a web application was the browser, now most of them support REST APIs, which allows them to be accessible on any device like mobile devices, tablets, apple watch, and any other digital gadgets. It doesn't matter whether you are working for software giants like Amazon, Facebook or Google or working with startups like Uber or Netflix, REST APIs are everywhere. When it comes to developing REST APIs in Java, there are a lot of choices available e.g. you can use JAX-RS based frameworks like Restlet and Jersey or you can use the Spring framework. I personally like Spring for de...

Top 20 Spring and REST Interview Questions Answers for Java/JEE Programmers

Gambar
Hello guys, I have been sharing a lot of REST with Spring tutorials from last a couple of weeks and today, I am going to share some of the frequently asked Spring and REST interview questions to Java developers applying for Web developer roles. Since Spring Framework is the most popular and the standard framework for developing Java web application and RESTful Web Services, a good knowledge of Spring core and Spring MVC is expected from any senior Java developer, but if the job description mention about REST and Web Services, you also need to be aware of how to develop RESTful Web Services using Spring Framework. From Spring 3.1, the framework has been enhanced a lot to support many features needed for RESTFul API out-of-the-box like HTTPMessageConverter can convert your HTTP response to JSON or XML by just detecting relevant library in classpaths like Jackson and JAXB. Spring also provides customized annotations for RESTful Web Services like @RestController which can make your C...

Top 5 Courses to Learn GraphQL for API Development in 2020 - Best of Lot

Gambar
Hello guys, you might have heard about GraphQL, another exciting technology. GraphQL is gaining a lot of popularity because of its superiority over traditional REST APIs. Many big companies like Facebook, Coursera, Github, and Yelp have already started using it, which has also helped a lot in terms of gaining popularity. There is a good chance that you might have already have heard about GraphQL in blogs pots, on Medium, or, in general, Web, but like many others, not sure whether it's worth learning or not, and if yes, from where to start. Well, I have been learning GraphQL since last week, and I would like to share some of the resources I have been using for my learning. If you happen to learn GraphQL, you can also get benefit from these courses, and if you happen to be a GraphQL expert, maybe you can advise if I am in the right direction or not. You can also suggest some of the tremendous GraphQL resources which are not mentioned in this list, and I should look. Anyway, before I ...