Close

JAX-RS - @PathParam Examples

JAX-RS JAVA EE 

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;

@Path("orders")
public class OrderService {

@GET
@Path("{orderId:\\d+}/items/{itemId:[a-z]\\d{2,3}}")
public String getOrderItemByItemId(@PathParam("orderId") String orderId,
@PathParam("itemId") String itemId) {
return "order id: " + orderId +
" and item id: " + itemId;
}

@GET
@Path("{orderId}/items/{itemId}")
public String getInvalidOrderItemByItemId(@PathParam("orderId") String orderId,
@PathParam("itemId") String itemId) {
return "The requested order id or item id are not valid. order id: " + orderId +
" and item id: " + itemId;
}
}
Original Post




import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;

@Path("/orders")
public class OrderService {

@GET
public String getOrders() {
return "returning all orders";
}

@GET
@Path("/{orderId}")
public String getOrderById(
@PathParam("orderId") String orderId) {
return "returning order with id " + orderId;
}

@GET
@Path("/{orderId}/items")
public String getOrderItemsById(@PathParam("orderId") String orderId) {
return "returning all order items by order id: " + orderId;
}

@GET
@Path("/{orderId}/items/{itemId}")
public String getOrderItemByItemId(@PathParam("orderId") String orderId,
@PathParam("itemId") String itemId) {
return "returning order item by order id: " + orderId +
" and item id: " + itemId;
}

}
Original Post




See Also