Hello guys, today's world is about Microservices and REST architecture is the one which powers Microservices. REST web services have quickly become the defacto web services in the web development world and have almost replaced SOAP-based web services that rule the world before. With the growing use of REST APIs in web technology space REST is also becoming increasingly important on J2EE and other web development interviews and if you say you know web-service then be prepare for some REST concept related questions.
Earlier, I have shared 15 Microservice Interview Questions and in this article, I have put together some of the basic and advanced REST web service questions together which will be useful to revise the concept before appearing for any REST web service interviews.
These questions are also quite useful for Java developers preparing for web development or fullstack developer interviews as REST APIs are everywhere and experience in developing RESTful Web service is highly desirable for all kinds of employers.
This article is in continuation of my earlier post on Interviews like Top Spring Interview Questions and Top Struts Interview Questions and if you haven't see them already then you can also checkout to prepare better as Spring and Struts are two of the most popular Java framework for web development.
And, if you are a complete beginner into RESTful web services then I also suggest you take a look at these REST Web Services online courses for Java programmers. It's a great hands-on course to learn how to develop RESTful web service in Java.
13 REST Web services Framework interview questions answers
Here is a list of my REST Interview questions, helpful for a quick review before going for any web services interview on Java J2EE.
1) What are REST and RESTful web services?
this is the first REST interview question on most of the interviews as not everybody familiar with REST and also start a discussion based on candidates response.
Anyway, REST stands for REpresentational State Transfer (REST) its a relatively new concept of writing web services that enforces a stateless client-server design where web services are treated as resources and can be accessed and identified by their URL, unlike SOAP web services which were defined by WSDL.
Web services written by apply REST Architectural concept are called RESTful web services which focus on System resources and how state of Resource should be transferred over http protocol to a different clients written in different languages. In RESTful web services http methods like GET, PUT, POST and DELETE can can be used to perform CRUD operations.
2) What is differences between RESTful web services and SOAP web services ?
Though both RESTful Web Services and SOAP web service can operate cross platform they are architecturally different to each other, here is some of differences between REST and SOAP:
1) REST is more simple and easy to use than SOAP
2) REST uses HTTP protocol for producing or consuming web services while SOAP uses XML.
3) REST is lightweight as compared to SOAP and preferred choice in mobile devices and PDA's.
5) REST web services call can be cached to improve performance.
These were key difference between REST and SOAP APIs and if you want to learn more differences you can also checkout my earlier post on RESTful vs SOAP APIs to learn more about this topic.
3) What is Restlet framework ?
Restlet is leading RESTful web framework for Java applications is used to build RESTFul web services it has two part Restlet API and a Restlet implementation much like Servlet specification. There are many implementation of Restlet framework available you just need to add there jar in your classpath to use them. By using Restlet web framework you can write client and server.
4) What is Resource in REST API and Restlet framework ?
Resource in REST API is any entity which you can access or modify. For example, a Bookstore may publish REST APIs to create, modify, and delete books and in that case Book is a resource. Like an API /book
It represent a "resource" in REST architecture. on RESTLET API it has life cycle methods like init(), handle() and release() and contains a Context, Request and Response corresponding to specific target resource.
This is now deprecated over ServerResource class and you should use that. You can further see Restlet documentation for more details.
5) Can you use Restlet without any web-container ?
Yes, Restlet framework provide default server which can be used to handle service request in web container is not available. This is very similar to Spring Boot which provides an embedded server like Tomcat and Jetty where you can run your web application without deploying it to another web server during development phase
6) What is difference between Restlets and Jersey ?
This REST web service interview questions is open for you all, post you answer in comment section. For those who wants hints, both are Java framework which allows you to create REST API much like Spring MVC and JAX-RS. You can also see my post difference between Restlet, JAX-RS,RESTEasy and Apache CXF for more details.
7) What is RESTEasy ?
RESTEasy is another REST framework introduced in JBoss Application Server. This was rather easy REST interview questions. you can answer in detail only if you have used this or working in JBoss. Actually there are many more frameworks which Java developer can use to create REST API like Spring MVC, JAX-RS, RESTlet, and Jersey, you can choose whatever you like.
If you want to learn more like when to use Jersey over RESTlet, you can see my earlier post about top 5 REST frameworks for Java developers, but when it comes to my favorite, I choose Spring MVC for REST API development almost always.
8) What are the tools used for creating RESTful web services ?
You can use AJAX(Asynchronous JavaScript with XAML) and Direct Web Removing to consume web service in web application. Both Eclipse and NetBeans also supported development of RESTFul services.
9) How to display custom error pages using RESTful web services ?
In order to customize error you need to extend StatusService and implement getRepresentation(Status, Request, Response) method with your custom code now assign instance of your CustomStatusService to appropriate "statusService property".
10) Which HTTP methods are supported by RestFull web services ?
Another common REST interview question regarding RESTFul web service each Resource supports GET, POST, PUT and DELETE http methods.GET is mapped to represent(), POST - acceptRepresentation(), PUT- storeRepresentation and DELET for rmeoveRepresentation.
11) What is the difference between the top-down and bottom-up approaches of developing web services?
In the top-down approach first WSDL document is created and then Java classes are developed based on the WSDL contract, so if the WSDL contract changes you got to change your Java classes while in the case of the bottom-up approach of web service development you first create Java code and then use annotations like @WebService to specify contract or interface and WSDL field will be automatically generated from your build.
12) What happens if RESTful resources are accessed by multiple clients? do you need to make it thread-safe?
Since a new Resource instance is created for every incoming Request there is no need to make it thread-safe or add synchronization. multiple clients can safely access RESTful resources concurrently.
13) What is difference between REST and GraphQL? (answer)
This is one of the most popular questions on REST which I have seen on recent interviews and its not surprising given industry is now moving towards GraphQL which address many of REST architecture shortcomings like over fetching and underfetching and versioning.
REST architecture always struggle to model relationship which is everywhere in real world. In case of REST APIs, you have resources and then APIS to create, modify, and delete those resources but you don't have any API to fetch two closely related resources.
For example, you want to retrieve, all the customers together with their orders. In case of REST, you need to first retrieve customers which will then expose REST APIs for orders and then you go and fetch them, this require a lot of request and wastage of time and bandwidth. GraphQL solves this problem by exposing schema where you can get all the data with just one endpoint. This solves the problem of over fetching and under fetching and also bandwidth and time wastage.
Here is a nice diagram which shows how REST and GraphQL works and it also highlight the difference between them.
You can clearly see that GraphQL allows us to retrieve multiple resource with just one query which was not possible with REST APIs. This solves a lot of problem and also improves performance.
That’s all on REST interview questions for Java and web developers. I have shared only popular questions so that you at least know the essential REST API concepts and how to develop them in Java programming language.
I will add a couple of more REST Interview questions whenever I got them from my friend circle, mostly advanced REST API questions on paging, security, and exception handling for experienced developers but if you got any feel free to share.
Some Interview questions articles you may like
P.S. - If you want to learn how to develop RESTful Web Services using Spring Framework, check out Eugen Paraschiv's REST with Spring course. He has recently launched the certification version of the course, which is full of exercises and examples to further cement the real world concepts you will learn from the course.
15 comments :
This article is riddled with errors and inconsistencies...
To point out a few:
- The RESTful architecture is not a 'relatively new concept' it was developed in parallel with HTTP. Maybe you mean it has increased in popularity for web services?
- It focuses on resources, not system resources
- It is simpler by design but not necessarily simpler to use - SOAP has a lot of tooling for quick generation of WSs
- "REST uses HTTP protocol for producing or consuming web services while SOAP uses XML." Well, no, more often than not SOAP uses HTTP as its transport layer. Requests to RESTful web services can be encoded in XML.
- And as far as thread safety, this should absolutely be a concern. A 'resource' in rest-speak is the noun - a customer, a receipt, a product and while the controller handling the request might have a new controller instance to handle each request, each of the services called by the controller to save or load these resource representations should be checked for thread safety. At some point you will probably query a database and you wont have an instance of your database for every request...
HI can u pls tell me what is the difference between RESTful webservices and HttpServlet.
I didn't see any difference between these two.
Just extra annotations.
thanks a lot
Peter
SOAP Web Service Still rules and if you are going to work for already existing Web Service or going to develop new Web Service client, you are likely to work with SOAP Web Service in Java. Most of the interview questions I face on J2EE interviews related to Web Services are related to SOAP Web Service and only few of them are from REST Web Service. One question which puzzled me is that does Java has special support for REST Web Service ?
Some more to add
What is the difference between put and post?
How authentication can be added on the restful web services?
Is this a new technology, or correct use of the http methods?
How threads are handled and what all Data structures are used in the restlet API, If one is using the restlet api?
How the pooling of the threads are maintained inside the reslet API?
What are the different API supports the restful services?
That is RESTful not RESTFull
What is the purpose of different HTTP request type in RESTful web services?
Can anyone please provide good website for RESTful webservices tutorials where we can understand the concepts very clearly ???
what is the difference between JSON and XML?
What are the Context Resolvers in Restful Services?
What is JAX-RS Injection in Restful services what are the methods are there in jax-rs injection?
What is the purpose of different HTTP request type in RESTful web services?
Answer :
HTTP GET : to retrieve something e.g an employee
HTTP POST : to store an object without id
HTTP PUT : to store an object with id
HTTP DELETE : to remove an object
Great questions, Please see here for some more RESTful WebService Interview Questions
I have faced below questions:
1) In Jersy implementation , Which jar should I include to convert JSON/XML request to POJO ?
2) How we can identify that particular webservice is accepting or generating particular input or output format?
3) How shall I handle exceptions in webservices ?
Can anyone help me with business scenarios where POST should be used? Is POST safer as compared to GET(found mixed answers for the same).
Answer to #6 question is:
Jersey framework has been provided by Oracle Where as RESTlet is another wat to provide implementation for JAX-RS Spec which has been introduced by Jboss server.
Post a Comment