Boas pessoal, estou a desenvolver um projeto em grails e necessito de desenvolver também a vertente mobile.
A minha dúvida está na parte de fazer o webservice visto que não tenho qualquer experiência nessa parte. Alguém me pode dar umas luzes ou sites para consultar? é que já andei a investigar e tenho a app mobile desenvolvida e consigo fazer o GET para a aplicação usando json mas não consigo de forma alguma fazer o POST para o servidor. Não sei se por culpa da aplicação mobile ou se por culpa do servidor. o meu controlador está assim:
Código :
A minha dúvida está na parte de fazer o webservice visto que não tenho qualquer experiência nessa parte. Alguém me pode dar umas luzes ou sites para consultar? é que já andei a investigar e tenho a app mobile desenvolvida e consigo fazer o GET para a aplicação usando json mas não consigo de forma alguma fazer o POST para o servidor. Não sei se por culpa da aplicação mobile ou se por culpa do servidor. o meu controlador está assim:
Código :
class OLDController {
static allowedMethods = [save: "POST", update: "PUT", delete: "DELETE"]
def index(Integer max) {
params.max = Math.min(max ?: 10, 100)
respond OLD.list(params), model:[OLDInstanceCount: OLD.count()]
}
def show(OLD OLDInstance) {
respond OLDInstance
}
def create() {
respond new OLD(params)
}
@Transactional
def save(OLD OLDInstance) {
if (OLDInstance == null) {
notFound()
return
}
if (OLDInstance.hasErrors()) {
respond OLDInstance.errors, view:'create'
return
}
OLDInstance.save flush:true
request.withFormat {
form {
flash.message = message(code: 'default.created.message', args: [message(code: 'OLDInstance.label', default: 'OLD'), OLDInstance.id])
redirect OLDInstance
}
'*' { respond OLDInstance, [status: CREATED] }
}
}
def edit(OLD OLDInstance) {
respond OLDInstance
}
@Transactional
def update(OLD OLDInstance) {
if (OLDInstance == null) {
notFound()
return
}
if (OLDInstance.hasErrors()) {
respond OLDInstance.errors, view:'edit'
return
}
OLDInstance.save flush:true
request.withFormat {
form {
flash.message = message(code: 'default.updated.message', args: [message(code: 'OLD.label', default: 'OLD'), OLDInstance.id])
redirect OLDInstance
}
'*'{ respond OLDInstance, [status: OK] }
}
}
@Transactional
def delete(OLD OLDInstance) {
if (OLDInstance == null) {
notFound()
return
}
OLDInstance.delete flush:true
request.withFormat {
form {
flash.message = message(code: 'default.deleted.message', args: [message(code: 'OLD.label', default: 'OLD'), OLDInstance.id])
redirect action:"index", method:"GET"
}
'*'{ render status: NO_CONTENT }
}
}
protected void notFound() {
request.withFormat {
form {
flash.message = message(code: 'default.not.found.message', args: [message(code: 'OLDInstance.label', default: 'OLD'), params.id])
redirect action: "index", method: "GET"
}
'*'{ render status: NOT_FOUND }
}
}
}
static allowedMethods = [save: "POST", update: "PUT", delete: "DELETE"]
def index(Integer max) {
params.max = Math.min(max ?: 10, 100)
respond OLD.list(params), model:[OLDInstanceCount: OLD.count()]
}
def show(OLD OLDInstance) {
respond OLDInstance
}
def create() {
respond new OLD(params)
}
@Transactional
def save(OLD OLDInstance) {
if (OLDInstance == null) {
notFound()
return
}
if (OLDInstance.hasErrors()) {
respond OLDInstance.errors, view:'create'
return
}
OLDInstance.save flush:true
request.withFormat {
form {
flash.message = message(code: 'default.created.message', args: [message(code: 'OLDInstance.label', default: 'OLD'), OLDInstance.id])
redirect OLDInstance
}
'*' { respond OLDInstance, [status: CREATED] }
}
}
def edit(OLD OLDInstance) {
respond OLDInstance
}
@Transactional
def update(OLD OLDInstance) {
if (OLDInstance == null) {
notFound()
return
}
if (OLDInstance.hasErrors()) {
respond OLDInstance.errors, view:'edit'
return
}
OLDInstance.save flush:true
request.withFormat {
form {
flash.message = message(code: 'default.updated.message', args: [message(code: 'OLD.label', default: 'OLD'), OLDInstance.id])
redirect OLDInstance
}
'*'{ respond OLDInstance, [status: OK] }
}
}
@Transactional
def delete(OLD OLDInstance) {
if (OLDInstance == null) {
notFound()
return
}
OLDInstance.delete flush:true
request.withFormat {
form {
flash.message = message(code: 'default.deleted.message', args: [message(code: 'OLD.label', default: 'OLD'), OLDInstance.id])
redirect action:"index", method:"GET"
}
'*'{ render status: NO_CONTENT }
}
}
protected void notFound() {
request.withFormat {
form {
flash.message = message(code: 'default.not.found.message', args: [message(code: 'OLDInstance.label', default: 'OLD'), params.id])
redirect action: "index", method: "GET"
}
'*'{ render status: NOT_FOUND }
}
}
}