This project is a proof of concept (POC) for Makersharks' search API. The API allows buyers to search for manufacturers based on customized requirements such as location, nature of business, and manufacturing processes.
- Supplier Search: Fetch a list of manufacturers based on specific criteria like location, nature of business, and manufacturing processes.
- Pagination Support: Supports pagination when the number of results exceeds a certain limit.
- Input Validation: Ensures only valid data is processed by the API.
- Exception Handling: Handles exceptions gracefully. (More security features are documented as TODOs)
- API Documentation: Includes Swagger documentation for easy interaction and testing of the API.
- Backend: Spring Boot (Java)
- Database: H2 (In-Memory Database for POC), SQL (connectivity is also demonstrated)
- Validation: Hibernate Validator
- Testing: JUnit and Mockito
- Documentation: Swagger (enabled)
- Java 17 or higher
- Maven 3.6+
-
Clone the Repository:
git clone https://github.com/armaansharmaa/SupplierSpringboot.git cd SupplierSpringboot -
Build the Project:
mvn clean install
-
Run the Application: Once the build is successful, run the application using:
mvn spring-boot:run
-
Access the API: The API will be accessible at:
http://localhost:8080 -
Access Swagger UI (Enabled): The API documentation and testing UI will be available at:
http://localhost:8080/swagger-ui.htmlSwagger can also be accessed using the OpenAPI JSON format at:
http://localhost:8080/v3/api-docs
The application demonstrates connectivity with both SQL and H2 databases. For the POC, H2 is used as the default database. On startup, it will auto-generate the necessary tables and populate them with sample data from data.sql. The configuration for both H2 and SQL databases is shown in the application.properties file.
To access the H2 console, go to:
http://localhost:8080/h2-console
Use the following credentials:
- JDBC URL:
jdbc:h2:mem:testdb - Username:
root - Password: '0000'
The data.sql file contains some initial test entries that will be loaded into the H2 database on startup.
Description: Retrieves a list of manufacturers matching the given criteria. The search is based on location, nature of business, and the capability to perform specific manufacturing processes. Supports pagination.
Request Body Example:
{
"location": "India",
"natureOfBusiness": "small_scale",
"manufacturingProcess": "3d_printing",
"page": 0,
"size": 10
}Response Example:
{
"totalPages": 1,
"totalElements": 1,
"size": 1,
"content": [
{
"supplierId": 1,
"companyName": "Company A",
"website": "http://companya.com",
"location": "India",
"natureOfBusiness": "small_scale",
"manufacturingProcesses": "3d_printing"
}
],
"number": 0,
"sort": {
"empty": true,
"unsorted": true,
"sorted": false
},
"numberOfElements": 1,
"pageable": {
"pageNumber": 0,
"pageSize": 1,
"sort": {
"empty": true,
"unsorted": true,
"sorted": false
},
"offset": 0,
"unpaged": false,
"paged": true
},
"first": true,
"last": true,
"empty": false
}To test the API, you can use the following cURL commands:
curl -X POST http://localhost:8080/api/supplier/query \
-H "Content-Type: application/json" \
-d '{
"location": "India",
"natureOfBusiness": "small_scale",
"manufacturingProcess": "3d_printing",
"page": 0,
"size": 10
}'curl -X POST http://localhost:8080/api/supplier/query \
-H "Content-Type: application/json" \
-d '{
"location": "USA",
"natureOfBusiness": "medium_scale",
"manufacturingProcess": "moulding",
"page": 0,
"size": 10
}'The API returns a structured response with pagination, containing the total number of pages, total elements, and the list of suppliers matching the criteria.
Response Fields:
totalPages: The total number of pages available.totalElements: The total number of manufacturers found.size: The number of results per page.content: A list of suppliers matching the criteria, including:supplierId: The unique identifier for the supplier.companyName: The name of the company.website: The website URL of the company.location: The location of the manufacturer.natureOfBusiness: The nature of business (e.g., small_scale, medium_scale, etc.).manufacturingProcesses: The manufacturing process (e.g., 3d_printing, moulding, etc.).
number: The current page number.sort: Sorting information.first: Boolean indicating if this is the first page.last: Boolean indicating if this is the last page.numberOfElements: The number of elements on the current page.pageable: Additional pagination information, such as the offset, page size, page number, etc.empty: Boolean indicating if the content is empty.
Run the unit tests using:
mvn testUnit tests cover:
- Validation of API inputs.
- Correct response structure.
- Handling of invalid or missing parameters.
- Input Validation: All inputs are validated to ensure only proper data is processed by the API.
- TODOs: Detailed security features such as authentication, authorization, and rate-limiting are planned but not yet implemented in the POC.
- Protection Against Attacks: SQL Injection is prevented by using parameterized queries and sanitized inputs.
- Security Enhancements: Implement OAuth2 for authentication and authorization.
- Rate Limiting: Prevent excessive querying from users.
- Caching: Add caching for frequent search queries to improve performance.
- Improved Exception Handling: Provide more granular error responses and handle specific error cases gracefully.
This project is licensed under the MIT License.
For any questions or issues, please contact Armaan Sharma.