Setup

REST Service

An application that will expose the REST endpoints needs one of the provided implementations by MicroStream or you need to implement the provided interfaces. In this example, we will use the Spark implementation that MicroStream provides.

Just add the dependency to your project, the logger is optional.

pom.xml
<dependencies>
   <dependency>
      <groupId>one.microstream</groupId>
      <artifactId>microstream-storage-restservice-sparkjava</artifactId>
      <version>08.01.02-MS-GA</version>
   </dependency>
   <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-simple</artifactId>
      <version>1.7.32</version>
   </dependency>
</dependencies>

Now use the resolver to connect the REST service to the storage, start it, and you’re good to go.

EmbeddedStorageManager storage = EmbeddedStorage.start();
if (storage.root() == null)
{
   storage.setRoot(new Object[] {
      LocalDate.now(),
      X.List("a", "b", "c"),
      1337
   });
   storage.storeRoot();
}

// create the REST service
StorageRestService service = StorageRestServiceResolver.resolve(storage);

// and start it
service.start();

That’s all you have to do to open the REST endpoints to access the stored data.

The base URL of the provided endpoints is per default: http://localhost:4567/microstream/ and you can find out all available endpoints on the root http://localhost:4567

Configuration

If you want to change the default port (4567) or instance name (microstream) it can be done by using the rest service implementation directly, and not go through the _Resolver` as in the previous snippet.

The Spark service can then be customized to your liking.

StorageRestServiceSparkJava service = StorageRestServiceSparkJava.New(storage);
service.setSparkService(
   Service.ignite().port(8888)
);
service.setInstanceName("my-name");

This will change the base URL to http://localhost/my-name/