You can use the @Endpoint
annotation to annotate resource methods and configure the various setting for the endpoint, such as transactions, security, and cache.
Use the following annotations when creating an endpoint method:
@Path
- When creating an endpoint method, use the@Path
annotation if there are additional path elements beyond the resource path or the sub-resource methods. The annotation is not required if the path is empty.@GET
,@POST
,@PUT
,@PATCH
, and,@DELETE
– These annotations are used as necessary when working with the endpoint.@Endpoint
– This annotation identifies the endpoint with a unique string ID. The ID does not change if the context or version changes. If the endpoint is for a singular resource, theisSingular
attribute must betrue
.
Naming Endpoint Annotations
When you define an ID in a @Endpoint
annotation, it is best to name it as a combination of the resource URI and the method request type. For example, a product resource might be:
@Endpoint(id="/products/{productId}#GET, isSingular = true)
Ordering Endpoint Annotations
When creating an endpoint, it is best to be consistent with the order of the annotations. For example:
@GET @Path("/{productId}") @Endpoint(id="/products/{productId}#GET", isSingular = true)
The following is an example of the metadata definitions of login endpoints of the CurrentUserRestResource
:
@POST @Endpoint(id = "/loginId", isSingular = true) public Object login(JSONObject pJSON) throws RestException {}