开发者

how to consume an external rest with grails JAX-RS?

I've been looking all over the internet trying to find an example of how to do this. I just want to consume an external REST server but i dont know how to set up the url of the external server , please help

import static org.grails.jaxrs.response.Responses.*

import javax.ws.rs.Consumes
import javax.ws.rs.GET
import javax.ws.rs.Produces
import javax.ws.rs.Path
import javax.ws.rs.PathParam
import javax.ws.rs.POST
import javax.ws.rs.core.Response

**@Path('http://localhost:8080/prueba3/api/person')**
@Consumes(['application/xml','application/json'])
@Produces(['application/xml','application/json'])
class PersonCollectionResource {

    @POST
    Response create(Person dto) {
        created 开发者_如何学Godto.save()
    }

    @GET
    Response readAll() {
        ok Person.findAll()
    }

    @Path('/{id}')
    PersonResource getResource(@PathParam('id') String id) {
        new PersonResource(id:id)
    }

}


if your project name is prubea3 you should define your path like this

@Path('/api/person')

your rest server can run another machine. it is not important for you. if your rest server running on localhost:8080 you should make request like this

http://localhost:8080/prueba3/api/person

i hope it is useful for you.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜