rest guidelines - eclipse-dirigible/dirigible GitHub Wiki
Rest Guidelines
API developers have to follow the rules below when creating new Rest endpoints
Separation of Processor and Service
This separation will allow us to separate the business logic from the end point definition.
- Create processor folder. Inside this folder add Processor class that contains the processing logic of an endpoint. This class can easy be unit tested.
โโโsrc
โ โโโโmain
โ โโโโjava
โ โ โโโโorg
โ โ โโโโeclipse
โ โ โโโโdirigible
โ โ โโโโruntime
โ โ โโโโtransport
โ โ โโโโprocessor
โ โ โ TransportProcessor.java
โ โ โ
โ โ โโโโservice
โ โ TransportProjectRestService.java
โ โ
โ โโโโresources
โ โโโโMETA-INF
โ โโโโservices
โ org.eclipse.dirigible.commons.api.service.IRestService
- Create service folder. Inside this folder add services that describes the rest endpoints. The service class should extends
org.eclipse.dirigible.commons.api.service.AbstractRestService
and implementsorg.eclipse.dirigible.commons.api.service.IRestService
.
public class TransportProjectRestService extends AbstractRestService implements IRestService {
@POST
@Path("/project/{workspace}")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.APPLICATION_JSON)
public Response importProject(@PathParam("workspace") String workspace) {
//call processor logic here
return Response.ok().build();
}
.......
You can check this code as an example: service-transport
- Inside META-INF folder create file org.eclipse.dirigible.commons.api.service.IRestService. Add the fully class name of your rest service, defined in service folder.
For example:
org.eclipse.dirigible.runtime.transport.service.TransportProjectRestService # Transport Project Service