Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
java
java
package demo.jaxrs.server;

import java.util.HashMap;
import java.util.Map;

import javax.ws.rs.HttpMethod;
import javax.ws.rs.ProduceMime;
import javax.ws.rs.UriParam;
import javax.ws.rs.UriTemplate;
import javax.ws.rs.core.HttpContext;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;

@UriTemplate("/customerservice/")
public class CustomerService {

    public CustomerService() {
    }

    @HttpMethod("GET")
    @UriTemplate("/customers/{id}/")
    public Customer getCustomer(@UriParam("id") String id) {
        ......
    }

    @HttpMethod("PUT")
    @UriTemplate("/customers/")
    public Response updateCustomer(Customer customer) {
        ......
    }

    @HttpMethod("POST")
    @UriTemplate("/customers/")
    public Response addCustomer(Customer customer) {
        ......
    }

    @HttpMethod("DELETE")
    @UriTemplate("/customers/{id}/")
    public Response deleteCustomer(@UriParam("id") String id) {
        ......
    }

    @UriTemplate("/orders/{orderId}/")
    public Order getOrder(@UriParam("orderId") String orderId) {
       ......
    }
}

...

@UriTemplate

@UriTemplate annotation can be is applied to resource classes or methods. The value of @UriTemplate annotation is a relative URI path follows the URI Template format. More information about URI Templates can be found from JAX-RS spec section 2.3 explains the usage of URI Templates.

@HttpMethod

@HttpMethod specifies the HTTP verb (GET, PUT, POST,DELETE) a method can accept.

...