diff --git a/api/api-samples/pom.xml b/api/api-samples/pom.xml
new file mode 100644
index 000000000..6b1e8b198
--- /dev/null
+++ b/api/api-samples/pom.xml
@@ -0,0 +1,31 @@
+
+
+
+
+ io.americanexpress.synapse
+ api
+ 0.4.16-SNAPSHOT
+
+
+ 4.0.0
+ api-samples
+ pom
+
+
+
+ sample-api-imperative-book
+
+
+
diff --git a/api/api-samples/sample-api-imperative-book/pom.xml b/api/api-samples/sample-api-imperative-book/pom.xml
new file mode 100644
index 000000000..7ef10be00
--- /dev/null
+++ b/api/api-samples/sample-api-imperative-book/pom.xml
@@ -0,0 +1,36 @@
+
+
+
+
+
+ api-samples
+ io.americanexpress.synapse
+ 0.4.16-SNAPSHOT
+
+
+ 4.0.0
+ sample-api-imperative-book
+
+
+
+ io.americanexpress.synapse
+ sample-service-imperative-book
+
+
+ io.americanexpress.synapse
+ synapse-api-rest-imperative
+
+
+
diff --git a/api/api-samples/sample-api-imperative-book/src/main/java/io/americanexpress/api/sample/imperativebook/BookApp.java b/api/api-samples/sample-api-imperative-book/src/main/java/io/americanexpress/api/sample/imperativebook/BookApp.java
new file mode 100644
index 000000000..f815b66c5
--- /dev/null
+++ b/api/api-samples/sample-api-imperative-book/src/main/java/io/americanexpress/api/sample/imperativebook/BookApp.java
@@ -0,0 +1,25 @@
+/*
+ * Copyright 2020 American Express Travel Related Services Company, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package io.americanexpress.api.sample.imperativebook;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+public class BookApp {
+
+ public static void main(String[] args) {
+ SpringApplication.run(BookApp.class, args);
+ }
+}
diff --git a/api/api-samples/sample-api-imperative-book/src/main/java/io/americanexpress/api/sample/imperativebook/config/BookApiConfig.java b/api/api-samples/sample-api-imperative-book/src/main/java/io/americanexpress/api/sample/imperativebook/config/BookApiConfig.java
new file mode 100644
index 000000000..f8d639555
--- /dev/null
+++ b/api/api-samples/sample-api-imperative-book/src/main/java/io/americanexpress/api/sample/imperativebook/config/BookApiConfig.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2020 American Express Travel Related Services Company, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package io.americanexpress.api.sample.imperativebook.config;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import io.americanexpress.synapse.api.rest.imperative.config.BaseApiImperativeRestConfig;
+import io.americanexpress.synapse.api.rest.imperative.interceptor.MetricInterceptor;
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
+
+/**
+ * Configuration class for the Book API.
+ *
+ * This class extends {@code BaseApiImperativeRestConfig} to provide custom configurations for the Book API,
+ * including component scanning and interceptor registration.
+ *
+ * @author Aziz Ali
+ */
+@ComponentScan({
+ "io.americanexpress.service.sample.imperativebook",
+ "io.americanexpress.api.sample.imperativebook"
+})
+@Configuration
+public class BookApiConfig extends BaseApiImperativeRestConfig {
+
+ /**
+ * Used to intercept requests for checking headers.
+ */
+ private final BookHttpHeadersInterceptor bookHttpHeadersInterceptor;
+
+
+ /**
+ * Constructor taking in objectMapper & metricInterceptor.
+ *
+ * @param defaultObjectMapper the default object mapper
+ * @param interceptor the metric interceptor
+ * @param bookHttpHeadersInterceptor the
+ */
+ public BookApiConfig(ObjectMapper defaultObjectMapper,
+ MetricInterceptor interceptor,
+ BookHttpHeadersInterceptor bookHttpHeadersInterceptor) {
+ super(defaultObjectMapper, interceptor);
+ this.bookHttpHeadersInterceptor = bookHttpHeadersInterceptor;
+ }
+
+ /**
+ * Takes any interceptor we provide and binds it to our service endpoint.
+ *
+ * @param registry the list of interceptors bound to our service
+ */
+ @Override
+ public void addInterceptors(InterceptorRegistry registry) {
+ registry.addInterceptor(this.bookHttpHeadersInterceptor).order(1);
+ super.addInterceptors(registry);
+ }
+
+}
diff --git a/api/api-samples/sample-api-imperative-book/src/main/java/io/americanexpress/api/sample/imperativebook/config/BookEndpoint.java b/api/api-samples/sample-api-imperative-book/src/main/java/io/americanexpress/api/sample/imperativebook/config/BookEndpoint.java
new file mode 100644
index 000000000..74e52c184
--- /dev/null
+++ b/api/api-samples/sample-api-imperative-book/src/main/java/io/americanexpress/api/sample/imperativebook/config/BookEndpoint.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2020 American Express Travel Related Services Company, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package io.americanexpress.api.sample.imperativebook.config;
+
+/**
+ * Configuration class for defining API endpoints related to books.
+ *
+ * This class provides a centralized location for managing endpoint paths used in the application. It is designed to
+ * prevent instantiation.
+ *
+ * @author Aziz Ali
+ */
+public class BookEndpoint {
+
+ /**
+ * The base endpoint for book-related API operations.
+ */
+ public static final String BOOKS_ENDPOINT = "/api/v1/books";
+
+ private BookEndpoint() {
+ }
+}
diff --git a/api/api-samples/sample-api-imperative-book/src/main/java/io/americanexpress/api/sample/imperativebook/config/BookHttpHeadersInterceptor.java b/api/api-samples/sample-api-imperative-book/src/main/java/io/americanexpress/api/sample/imperativebook/config/BookHttpHeadersInterceptor.java
new file mode 100644
index 000000000..4b75c5efd
--- /dev/null
+++ b/api/api-samples/sample-api-imperative-book/src/main/java/io/americanexpress/api/sample/imperativebook/config/BookHttpHeadersInterceptor.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2020 American Express Travel Related Services Company, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package io.americanexpress.api.sample.imperativebook.config;
+
+import io.americanexpress.synapse.api.rest.imperative.interceptor.BaseHttpInterceptor;
+import org.springframework.stereotype.Component;
+import java.util.List;
+
+/**
+ * Intercepts HTTP requests to validate required headers for book-related APIs.
+ *
+ * @author Aziz Ali
+ */
+@Component
+public class BookHttpHeadersInterceptor extends BaseHttpInterceptor {
+
+ /**
+ * Provides the list of required HTTP header names.
+ *
+ * @return list of required header names
+ */
+ @Override
+ protected List getRequiredHttpHeaderNames() {
+ return requiredHttpHeaderNames.stream().toList();
+ }
+}
diff --git a/api/api-samples/sample-api-imperative-book/src/main/java/io/americanexpress/api/sample/imperativebook/controller/CreateBookController.java b/api/api-samples/sample-api-imperative-book/src/main/java/io/americanexpress/api/sample/imperativebook/controller/CreateBookController.java
new file mode 100644
index 000000000..d0f17767b
--- /dev/null
+++ b/api/api-samples/sample-api-imperative-book/src/main/java/io/americanexpress/api/sample/imperativebook/controller/CreateBookController.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2020 American Express Travel Related Services Company, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package io.americanexpress.api.sample.imperativebook.controller;
+
+import io.americanexpress.service.sample.imperativebook.model.CreateBookServiceRequest;
+import io.americanexpress.service.sample.imperativebook.model.CreateBookServiceResponse;
+import io.americanexpress.service.sample.imperativebook.service.CreateBookService;
+import io.americanexpress.synapse.api.rest.imperative.controller.BaseCreateImperativeRestController;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+import static io.americanexpress.api.sample.imperativebook.config.BookEndpoint.BOOKS_ENDPOINT;
+
+/**
+ * Controller for handling HTTP POST requests to create books. Extends the base class to utilize common create
+ * functionality.
+ *
+ * @author Aziz Ali
+ */
+@RequestMapping(BOOKS_ENDPOINT)
+@RestController
+public class CreateBookController extends BaseCreateImperativeRestController<
+ CreateBookServiceRequest,
+ CreateBookServiceResponse,
+ CreateBookService> {
+}
diff --git a/api/api-samples/sample-api-imperative-book/src/main/java/io/americanexpress/api/sample/imperativebook/controller/DeleteBookController.java b/api/api-samples/sample-api-imperative-book/src/main/java/io/americanexpress/api/sample/imperativebook/controller/DeleteBookController.java
new file mode 100644
index 000000000..40334bc7a
--- /dev/null
+++ b/api/api-samples/sample-api-imperative-book/src/main/java/io/americanexpress/api/sample/imperativebook/controller/DeleteBookController.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2020 American Express Travel Related Services Company, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package io.americanexpress.api.sample.imperativebook.controller;
+
+import io.americanexpress.service.sample.imperativebook.model.DeleteBookServiceRequest;
+import io.americanexpress.service.sample.imperativebook.model.DeleteBookServiceResponse;
+import io.americanexpress.service.sample.imperativebook.service.DeleteBookService;
+import io.americanexpress.synapse.api.rest.imperative.controller.BaseDeleteImperativeRestController;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+import static io.americanexpress.api.sample.imperativebook.config.BookEndpoint.BOOKS_ENDPOINT;
+
+/**
+ * Controller for handling HTTP DELETE requests to delete books. Extends the base class to utilize common delete
+ * functionality.
+ *
+ * @author Aziz Ali
+ */
+@RequestMapping(BOOKS_ENDPOINT)
+@RestController
+public class DeleteBookController extends BaseDeleteImperativeRestController<
+ DeleteBookServiceRequest,
+ DeleteBookServiceResponse,
+ DeleteBookService> {
+
+}
diff --git a/api/api-samples/sample-api-imperative-book/src/main/java/io/americanexpress/api/sample/imperativebook/controller/ReadBookController.java b/api/api-samples/sample-api-imperative-book/src/main/java/io/americanexpress/api/sample/imperativebook/controller/ReadBookController.java
new file mode 100644
index 000000000..4bdc3dd20
--- /dev/null
+++ b/api/api-samples/sample-api-imperative-book/src/main/java/io/americanexpress/api/sample/imperativebook/controller/ReadBookController.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2020 American Express Travel Related Services Company, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package io.americanexpress.api.sample.imperativebook.controller;
+
+import io.americanexpress.service.sample.imperativebook.model.ReadBookServiceRequest;
+import io.americanexpress.service.sample.imperativebook.model.ReadBookServiceResponse;
+import io.americanexpress.service.sample.imperativebook.service.ReadBookService;
+import io.americanexpress.synapse.api.rest.imperative.controller.BaseReadMonoImperativeRestController;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+import static io.americanexpress.api.sample.imperativebook.config.BookEndpoint.BOOKS_ENDPOINT;
+
+/**
+ * Controller for handling HTTP GET requests to read book details. Extends the base class to utilize common read
+ * functionality.
+ *
+ * @author Aziz Ali
+ */
+@RequestMapping(BOOKS_ENDPOINT)
+@RestController
+public class ReadBookController extends BaseReadMonoImperativeRestController<
+ ReadBookServiceRequest,
+ ReadBookServiceResponse,
+ ReadBookService> {
+}
diff --git a/api/api-samples/sample-api-imperative-book/src/main/java/io/americanexpress/api/sample/imperativebook/controller/UpdateBookController.java b/api/api-samples/sample-api-imperative-book/src/main/java/io/americanexpress/api/sample/imperativebook/controller/UpdateBookController.java
new file mode 100644
index 000000000..7608d7eba
--- /dev/null
+++ b/api/api-samples/sample-api-imperative-book/src/main/java/io/americanexpress/api/sample/imperativebook/controller/UpdateBookController.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2020 American Express Travel Related Services Company, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package io.americanexpress.api.sample.imperativebook.controller;
+
+import io.americanexpress.service.sample.imperativebook.model.UpdateBookServiceRequest;
+import io.americanexpress.service.sample.imperativebook.model.UpdateBookServiceResponse;
+import io.americanexpress.service.sample.imperativebook.service.UpdateBookService;
+import io.americanexpress.synapse.api.rest.imperative.controller.BaseUpdateImperativeRestController;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+import static io.americanexpress.api.sample.imperativebook.config.BookEndpoint.BOOKS_ENDPOINT;
+
+/**
+ * Controller for handling HTTP PUT requests to update book details. Extends the base class to utilize common update
+ * functionality.
+ *
+ * @author Aziz Ali
+ */
+@RequestMapping(BOOKS_ENDPOINT)
+@RestController
+public class UpdateBookController extends BaseUpdateImperativeRestController<
+ UpdateBookServiceRequest,
+ UpdateBookServiceResponse,
+ UpdateBookService> {
+
+}
diff --git a/api/pom.xml b/api/pom.xml
index 52043dfab..4eefec4f9 100644
--- a/api/pom.xml
+++ b/api/pom.xml
@@ -29,5 +29,6 @@
synapse-api-rest-imperative
synapse-api-rest-reactive
+ api-samples
diff --git a/service/service-samples/sample-service-imperative-book/src/main/java/io/americanexpress/service/sample/imperativebook/model/BaseBook.java b/service/service-samples/sample-service-imperative-book/src/main/java/io/americanexpress/service/sample/imperativebook/model/BaseBook.java
index de0f71c40..09c8b16ba 100644
--- a/service/service-samples/sample-service-imperative-book/src/main/java/io/americanexpress/service/sample/imperativebook/model/BaseBook.java
+++ b/service/service-samples/sample-service-imperative-book/src/main/java/io/americanexpress/service/sample/imperativebook/model/BaseBook.java
@@ -13,6 +13,8 @@
*/
package io.americanexpress.service.sample.imperativebook.model;
+import jakarta.validation.constraints.NotEmpty;
+
/**
* BaseBook class is responsible for creating the base book.
*
@@ -23,11 +25,13 @@ public class BaseBook {
/**
* Title of the book.
*/
+ @NotEmpty
private String title;
/**
* Author of the book.
*/
+ @NotEmpty
private String author;
/**
diff --git a/service/service-samples/sample-service-imperative-book/src/main/java/io/americanexpress/service/sample/imperativebook/service/CreateBookService.java b/service/service-samples/sample-service-imperative-book/src/main/java/io/americanexpress/service/sample/imperativebook/service/CreateBookService.java
index 1a0b4baa7..034cb1855 100644
--- a/service/service-samples/sample-service-imperative-book/src/main/java/io/americanexpress/service/sample/imperativebook/service/CreateBookService.java
+++ b/service/service-samples/sample-service-imperative-book/src/main/java/io/americanexpress/service/sample/imperativebook/service/CreateBookService.java
@@ -18,6 +18,7 @@
import io.americanexpress.service.sample.imperativebook.service.helper.CreateBookServiceResponseCreator;
import io.americanexpress.synapse.service.imperative.service.BaseService;
import org.springframework.stereotype.Component;
+import org.springframework.validation.annotation.Validated;
/**
* CreateBookService class is responsible for creating the book service.
@@ -25,6 +26,7 @@
* @author Francois Gutt
*/
@Component
+@Validated
public class CreateBookService extends BaseService<
CreateBookServiceRequest,
CreateBookServiceResponse
diff --git a/service/service-samples/sample-service-imperative-book/src/main/java/io/americanexpress/service/sample/imperativebook/service/DeleteBookService.java b/service/service-samples/sample-service-imperative-book/src/main/java/io/americanexpress/service/sample/imperativebook/service/DeleteBookService.java
index 12cb93bd8..8d8be4703 100644
--- a/service/service-samples/sample-service-imperative-book/src/main/java/io/americanexpress/service/sample/imperativebook/service/DeleteBookService.java
+++ b/service/service-samples/sample-service-imperative-book/src/main/java/io/americanexpress/service/sample/imperativebook/service/DeleteBookService.java
@@ -17,6 +17,7 @@
import io.americanexpress.service.sample.imperativebook.model.DeleteBookServiceResponse;
import io.americanexpress.synapse.service.imperative.service.BaseService;
import org.springframework.stereotype.Component;
+import org.springframework.validation.annotation.Validated;
/**
* DeleteBookService class is responsible for deleting the book service.
@@ -24,6 +25,7 @@
* @author Francois Gutt
*/
@Component
+@Validated
public class DeleteBookService extends BaseService<
DeleteBookServiceRequest,
DeleteBookServiceResponse
diff --git a/service/service-samples/sample-service-imperative-book/src/main/java/io/americanexpress/service/sample/imperativebook/service/ReadBookService.java b/service/service-samples/sample-service-imperative-book/src/main/java/io/americanexpress/service/sample/imperativebook/service/ReadBookService.java
index 974e0d7c1..d4397fbc5 100644
--- a/service/service-samples/sample-service-imperative-book/src/main/java/io/americanexpress/service/sample/imperativebook/service/ReadBookService.java
+++ b/service/service-samples/sample-service-imperative-book/src/main/java/io/americanexpress/service/sample/imperativebook/service/ReadBookService.java
@@ -18,6 +18,7 @@
import io.americanexpress.service.sample.imperativebook.service.helper.ReadBookServiceResponseCreator;
import io.americanexpress.synapse.service.imperative.service.BaseService;
import org.springframework.stereotype.Component;
+import org.springframework.validation.annotation.Validated;
/**
* {@code ReadBookService} class is responsible for reading the book service.
@@ -25,6 +26,7 @@
* @author Francois Gutt
*/
@Component
+@Validated
public class ReadBookService extends BaseService<
ReadBookServiceRequest,
ReadBookServiceResponse
diff --git a/service/service-samples/sample-service-imperative-book/src/main/java/io/americanexpress/service/sample/imperativebook/service/UpdateBookService.java b/service/service-samples/sample-service-imperative-book/src/main/java/io/americanexpress/service/sample/imperativebook/service/UpdateBookService.java
index 33ea6044e..caf2aabdc 100644
--- a/service/service-samples/sample-service-imperative-book/src/main/java/io/americanexpress/service/sample/imperativebook/service/UpdateBookService.java
+++ b/service/service-samples/sample-service-imperative-book/src/main/java/io/americanexpress/service/sample/imperativebook/service/UpdateBookService.java
@@ -18,6 +18,7 @@
import io.americanexpress.service.sample.imperativebook.service.helper.UpdateBookServiceResponseCreator;
import io.americanexpress.synapse.service.imperative.service.BaseService;
import org.springframework.stereotype.Component;
+import org.springframework.validation.annotation.Validated;
/**
* UpdateBookService class is responsible for updating the book service.
@@ -25,6 +26,7 @@
* @author Francois Gutt
*/
@Component
+@Validated
public class UpdateBookService extends BaseService<
UpdateBookServiceRequest,
UpdateBookServiceResponse
@@ -51,7 +53,6 @@ public UpdateBookService(UpdateBookServiceResponseCreator updateBookServiceRespo
*/
@Override
protected UpdateBookServiceResponse doExecute(UpdateBookServiceRequest request) {
- var response = updateBookServiceResponseCreator.create(request);
- return response;
+ return updateBookServiceResponseCreator.create(request);
}
}