Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions api/api-samples/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>io.americanexpress.synapse</groupId>
<artifactId>api</artifactId>
<version>0.4.16-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
<artifactId>api-samples</artifactId>
<packaging>pom</packaging>

<!--Modules-->
<modules>
<module>sample-api-imperative-book</module>
</modules>

</project>
36 changes: 36 additions & 0 deletions api/api-samples/sample-api-imperative-book/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<parent>
<artifactId>api-samples</artifactId>
<groupId>io.americanexpress.synapse</groupId>
<version>0.4.16-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
<artifactId>sample-api-imperative-book</artifactId>

<dependencies>
<dependency>
<groupId>io.americanexpress.synapse</groupId>
<artifactId>sample-service-imperative-book</artifactId>
</dependency>
<dependency>
<groupId>io.americanexpress.synapse</groupId>
<artifactId>synapse-api-rest-imperative</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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.
* <p>
* 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);
}

}
Original file line number Diff line number Diff line change
@@ -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.
* <p>
* 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() {
}
}
Original file line number Diff line number Diff line change
@@ -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<String> getRequiredHttpHeaderNames() {
return requiredHttpHeaderNames.stream().toList();
}
}
Original file line number Diff line number Diff line change
@@ -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> {
}
Original file line number Diff line number Diff line change
@@ -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> {

}
Original file line number Diff line number Diff line change
@@ -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> {
}
Original file line number Diff line number Diff line change
@@ -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> {

}
1 change: 1 addition & 0 deletions api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@
<!-- Base api Synapse dependencies-->
<module>synapse-api-rest-imperative</module>
<module>synapse-api-rest-reactive</module>
<module>api-samples</module>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @aazizali
Can this module be renamed to synapse-api-samples? This keeps your naming consistent with other modules.

</modules>
</project>
Loading