Skip to content
Antoaneta edited this page Aug 17, 2021 · 2 revisions

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.

  1. 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
  1. 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 implements org.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

  1. 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