Grails as a pure REST backend good? Having technical difficulties to follow the documentation.

85 views
Skip to first unread message

martin...@n-xt.de

unread,
Jan 21, 2016, 7:45:24 AM1/21/16
to Grails Dev Discuss
Dear all,

(1) I had been working with Grails many years back. Looking for a good backend framework now (frontend will use angular.js). My first question is whether Grails is still a good choice to provide pure REST services?

(2) I tried to follow the documentation (section 9.1.5.1). I have created a domain class called "Restaurant" having two attributes (title, website). Then I have created a RestaurantController having following code:

import grails.rest.RestfulController
import grails.transaction.*

@Transactional(readOnly = false)
class RestaurantController extends RestfulController  {

 
static responseFormats = ['xml', 'json']

 
RestaurantController() {
   
super(Restaurant)
 
}

}

I have sent a POST request to the URI "http://localhost:8080/restaurant" with following content "title=Asia+Imbiss&website=www.asia-imbiss.com". But no matter which URL I use I get a java.lang.NullPointerException exception caused by Cannot invoke method count() on null object (see screenshot). What am I doing wrong here?

Btw: If I don't create a controller and use the @Resource(uri='/restaurant')like stated in 9.1.1, it works fine!








martin...@n-xt.de

unread,
Jan 22, 2016, 6:16:05 AM1/22/16
to Grails Dev Discuss
I think i found the issue. It is workign, however, not with the URIs provided in the documentation:



If I want to save a new entry, I need to request the URI "/restaurant/save" and if I want to view an existing data set I need to request e.g. "/restaurant/show/1"

Jeff Scott Brown

unread,
Jan 22, 2016, 9:35:46 AM1/22/16
to grails-de...@googlegroups.com

> On Jan 22, 2016, at 5:16 AM, martin...@n-xt.de wrote:
>
> I think i found the issue. It is workign, however, not with the URIs provided in the documentation:
>
>
>
>
>
> If I want to save a new entry, I need to request the URI "/restaurant/save" and if I want to view an existing data set I need to request e.g. "/restaurant/show/1”
>

I expect you have a problem with your url mappings. You probably want something like this…

“/restaurants"(resources: ‘restaurant’)

See https://github.com/jeffbrown/restaurants.



JSB

Jeff Scott Brown
Principal Software Engineer
Grails Development Team
Object Computing Inc.
http://www.ociweb.com/

Autism Strikes 1 in 166
Find The Cause ~ Find The Cure
http://www.autismspeaks.org/

Reply all
Reply to author
Forward
0 new messages