miércoles, 22 de febrero de 2017

WS-REST 04. Otros pequeños parámetros

Creemos esta clase de respuesta:


package main.java.org.ximodante.jersey;

import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Response;

@Path("/helloWorldREST")
public class HelloWorldREST {

  @GET
  @Path("/{parameter}")
  public Response responseMsg( 
    @PathParam("parameter") String parameter,
    @DefaultValue("Nothing to say") @QueryParam("value") String value) {

      String output = "Hello from: " + parameter + " : " + value;

      return Response.status(200).entity(output).build();
  }
}

Aquí tenemos las anotaciones @Path que hay que añadir a nuestra ruta y tambiém los parámetros que se deberán añadir.

Si ejecutamos esta ruta http://localhost/Jersey04/rest/helloWordREST/Ximo nos mostrará:

Hello from: Ximo : Nothing to say

No hay comentarios :

Publicar un comentario