private CompletionStage<RestResponse> createCounter(RestRequest request) throws RestResponseException {
      NettyRestResponse.Builder responseBuilder = invocationHelper.newResponse(request);
      String counterName = request.variables().get("counterName");

      String contents = request.contents().asString();

      if (contents == null || contents.isEmpty()) {
         throw Log.REST.missingContent();
      }
      CounterConfiguration configuration = createCounterConfiguration(contents);
      if (configuration == null) {
         throw Log.REST.invalidContent();
      }

      return invocationHelper.getCounterManager()
            .defineCounterAsync(counterName, configuration)
            .thenApply(created -> created ?
                  responseBuilder.build() :
                  responseBuilder.status(NOT_MODIFIED)
                        .entity("Unable to create counter: " + counterName)
                        .build());
   }
@Test
   public void testCounterCreation() {
      String counterName = "counter-creation";
      createCounter(counterName, CounterConfiguration.builder(CounterType.WEAK).initialValue(1).build());
      assertThat(doCounterCreateRequest(counterName, CounterConfiguration.builder(CounterType.WEAK).initialValue(1).build())).isNotModified();
      assertThat(doCounterCreateRequest(counterName, CounterConfiguration.builder(CounterType.BOUNDED_STRONG).initialValue(2).build())).isNotModified();
   }