0

An answer to the following question Difference between RESTful webservice and HttpServlet says "REST is really an architectural style used when designing an API on a server. HttpServlets can be a method of implementing a RESTful web service".

In that case, can i say that if i implement an HTTPServlet that can get a resource, let's say it accepts unique Employee Id and returns Employee object as atleast partially RESTful web service?

For example, Let's say i have written a servlet which accepts a unique employee id, and returns a JSON string that represents an employee object. This object includes Id, name & designation of that employee. The url looks like : http://hostname:port/Rest/Employee/{id} .

Here id is the unique id for an employee. The following request gets me an employee with id as 1001:

http://hostname:port/Rest/Employee/1001

The response is a string, which looks like:

{"id": "1001", "name":"ayushi", "designation":"software engineer"}

My question here is: Can i call this as a RESTful web service?

Community
  • 1
  • 1
Ayushi
  • 405
  • 1
  • 9
  • 19
  • 2
    "at least partially RESTful". Yes. Every service that implements the REST architectural style *partially* is *partially* RESFtul. But this means nothing. –  Mar 02 '15 at 08:09
  • Lutz, thanks for your quick reply. Can you please elaborate a bit. What harm will it make if i implement it in HTTPServlet way, n what benefits will i get if i develop a fully Restful Web service. Provided, i have just one client to consume both of them. – Ayushi Mar 02 '15 at 08:12
  • 1
    Not unless you ask a concrete question. Describe in more detail what your Servlet does, how the URL looks like, what the result is. Try to identify the REST Resources. Perhaps then we can judge if there is anything un-RESTful in you approach. –  Mar 02 '15 at 08:13
  • Lutz, i have edited my comment. Please have a look. – Ayushi Mar 02 '15 at 08:15
  • 1
    Don't edit your comment, [edit your question](https://stackoverflow.com/posts/28805114/edit). –  Mar 02 '15 at 08:15
  • REST is a *concept*; a Servlet is an implementation of the HTTP specification. Apples and bulldozers comparison, your question completely over simplifies the entire concept and conflates two things that are not comparable. Your example if it is not imdepotent `GET` and Stateless is not REST it is just a convention for building URLS. **This is way too broad of a topic for SO** Hint: `JAX-RS` –  Mar 03 '15 at 05:07
  • Sure Jarrod, my question is, can we use servlets like the way i did to achieve RESTful web services? Is the example i have quoted a RESTful web service? Is it correct that HTTPServlet can be a method of implementing RESTful web service? – Ayushi Mar 03 '15 at 05:10

1 Answers1

0

This link could help you to know the structure of a RESTful service:

Servlets aren't designed for RESTful services "explicitely" but you can leverage them to implement such services like the way you did.

In fact, servlets don't integrate / define concepts of REST within their APIs. I mean resources, path variables, representations, conneg (content negociation). So you need something above / additional stuff to implement this.

A REST framework like Restlet directly provides such concepts within its API.

Hope it helps you, Thierry

Thierry Templier
  • 198,364
  • 44
  • 396
  • 360
  • That's correct Thierry. Got a chance to read about JAX-RS and i found the answer to my question. Over the years, Servlets has been a way of writing REST web service. But, JAX-RS simplifies the RESTFul service implementation. – Ayushi Dec 13 '15 at 13:49