-
Notifications
You must be signed in to change notification settings - Fork 93
rest guidelines
Antoaneta edited this page Aug 17, 2021
·
2 revisions
API developers have to follow the rules below when creating new Rest endpoints
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