What if I create a simple controller in Groovy & Grails and use it as Rest API Controller, other then extending RestFulController? - rest

I am using Groovy & Grails , and I wanted the difference between using nomal Grails controller as Rest Controller the using RestFulController class.And secondly I wanted to know which API implementation (Jersey or RestEasy) is Grails using at it's end.

I wanted the difference between using nomal Grails controller as Rest
Controller the using RestFulController class.
The difference would depend what you put in your normal Grails controller. If you put the same behavior in your normal controller as is provided by RestfulController, then of course there would be no functional difference. If you did not put the same behavior in your normal controller as is provided by RestfulController, then the details of what you put in your controller will dictate the differences between it and RestfulController.
RestfulController provides basic CRUD capability and a number of methods designed for extension to customize that behavior. See https://github.com/grails/grails-core/blob/v3.3.9/grails-plugin-rest/src/main/groovy/grails/rest/RestfulController.groovy.
And secondly I wanted to know which API implementation (Jersey or
RestEasy) is Grails using at it's end.
Grails is not using Jersey or RestEasy. Grails implements its own API.

Related

Document custom annotation in spring rest docs

I have to integrate spring rest docs in a legacy project were they use a bunch of custom annotation (such as for example the user roles).
Is there a way in spring rest docs to document this annotation?
Spring REST Docs works at the level of HTTP requests and responses. By design, it doesn't know anything about annotations or how those requests are handled and the responses created. This ensures that what you're documenting is at the same level as a client interacting with your service over HTTP.
If you want to include information about #PreAuthorize or an annotation that is similar to it, you will have to write something yourself to do that. If you want to fit into the REST Docs way of doing things, you could implement a custom Snippet that's configured with a class or method from which it extracts the annotation using reflection and generates some documentation from it.

JAX-RS Struts2 REST API

Why would one like to integrate JAX-RS(Jersey) using Rest API to Struts2? Struts2 is itself a mvc framework, so why would anyone want to integrate these both? If combined, how will the resulting framework be(I wanted to know if REST API just control the controller part of MVC).
There is a RESTful plugin called struts2-rest-plugin that has been included with the framework since version 2.1.1. A fair amount of information on the plugin can be found here.
Essentially, the plugin uses a custom action mapper that examines the request and based upon the HTTP Method used in conjunction with the URI, it dispatches the request to one of several different method names (e.g. GET /movies dispatched to index() method of action).
Just because Struts2 is an action-based framework does not mean a RESTful solution cannot be included as an alternative for developers. Spring MVC offers similar solutions themselves and it is also an action-based framework.
If you consider your JSON response as your view, you'll see that the fact that Struts2 is based on MVC design makes logical sense. Your model is simply the data structure you are returning to the client and your controller is the action.
Consider reading the link above on the plugin and you'll get a better picture of how the two can be integrated. If you want to return JSON but don't necessarily want to offer RESTful URLs in your Struts2 application, you can also consider the JSON plugin, found here.
I am not sure about Struts2, but in the past Struts1 did not have a "Rest" adapter built in. Jersey provides the cool #annotations that will easily serialize your datamodel and will push you in a "Restful" direction. Jersey does not provide an MVC framework as much as it provides convenience methods to work in a Restful/resource based way.

Support for annotation inheritance in Jersey

I am working on creating a SOA project. I want to use Jersey to expose the services on rest. In my project the standard is to create a API project which has API interfaces and DTOs. The implementation project depends on the API project and all implementation is written in the implementation.
The idea behind this architecture is that, we could create two API projects one for REST and other for SOAP, annotate the interfaces with required annotations. As a result the implementation would be unaware about the method used to expose the service (I mean REST and SOAP).
But the problem in Jersey is unable to discover the annotations on the interface and keeps throwing following exception
com.sun.jersey.api.container.ContainerException: The ResourceConfig instance does not contain any root resource classes.
A similar question has already been asked - JAX-RS Jersey/Grizzly Define an interface resource - The answer says that it is possible using Spring-Jersey.
But I tried various configuration options for spring-jersey - including - http://jersey.java.net/nonav/apidocs/1.8/contribs/jersey-spring/com/sun/jersey/spi/spring/container/servlet/package-summary.html
But did not have any success.
Questions
The idea of trying to manage the different ways of exposing service thru interface, is it a feasible and good idea? How are experts in the industry doing?
How can I manage to use Jersey to understand the annotations done on Interface?
Is some other framework like RestEasy going to help?

grails + gwt request handling via controllers

I am new to gwt. I am trying to integrate gwt+grails.Can anybody provide me a good example for handling the request using grails controllers and not a custom servlet.I will be really thankful if anybody can guide me :)
I had some success by returning json from grails controllers. Look here for more info. Then, on the gwt client side, create javascript "overlay" types, and then use RequestBuilder to make a request to the grails controller to retrieve json. Here is a good tutorial, but you can skip the section that describes how to create a servlet to return json, because your grails controllers will do that.

Implementation differences between Zend_Rest_Server & Zend_Rest_Controller

There seems to be two different ways in the Zend Framework to implement a RESTful API, one by adding objects&functions to the Zend Rest Server object inside a action controller, the other through extending the very sparsely documented Zend Rest Controller method mentioned in the Zend Rest Router configuration.
My questions are:
Do you configure the Router to point at the Zend_Rest server or
Do you extend the Zend_Rest_Controller class and instantiate business objects inside action methods?
Thanks!
You should use Zend_Rest_Route and extend Zend_Rest_Controller.
Zend_Rest is far from beeind RESTfull its more of another RPC.