rest icon indicating copy to clipboard operation
rest copied to clipboard

Some way to disambiguate ambiguous resource methods on the server

Open derekm opened this issue 6 years ago • 0 comments

With Jersey's WebResourceFactory and MicroProfile's Rest Client, re-using the same JAX-RS-annotated interfaces on the client-side and the server-side is becoming more common.

When the server-side methods have arguments, it becomes convenient to overload those methods for the sake of the client-side, so that clients aren't forced to pass nulls when parameters are optional.

For example, on the client-side, I want this resource interface:

/**
 *  URI provides default behaviors associated with collections of entities.
 */
public interface CollectionResource<O extends ResourceObject, P extends ObjectParams> {

    /**
     * For some object type, retrieve the entire collection.
     * @return list of objects
     */
    @GET
    @Produces({MediaType.APPLICATION_JSON})
    default List<O> get() {
        return get(null);
    }

    /**
     * For some object type, retrieve the entire collection.
     * @param params parameters to filter the collection by
     * @return list of objects
     */
    @GET
    @Produces({MediaType.APPLICATION_JSON})
    List<O> get(@BeanParam P params);

    /**
     * For some object type, create an entry.
     * @param object object to create
     * @return created object
     */
    @POST
    @Consumes({MediaType.APPLICATION_JSON})
    @Produces({MediaType.APPLICATION_JSON})
    O post(O object);

}

but on the server-side I want this resource interfaces:

/**
 *  URI provides default behaviors associated with collections of entities.
 */
public interface CollectionResource<O extends ResourceObject, P extends ObjectParams> {

    /**
     * For some object type, retrieve the entire collection.
     * @param params parameters to filter the collection by
     * @return list of objects
     */
    @GET
    @Produces({MediaType.APPLICATION_JSON})
    List<O> get(@BeanParam P params);

    /**
     * For some object type, create an entry.
     * @param object object to create
     * @return created object
     */
    @POST
    @Consumes({MediaType.APPLICATION_JSON})
    @Produces({MediaType.APPLICATION_JSON})
    O post(O object);

}

Some way to re-use the 1st interface on both client- and server-sides while indicating to the server-side how to disambiguate the interface would be ideal.

derekm avatar Oct 22 '19 15:10 derekm