This project is a Spring Boot application that provides APIs to manipulate and retrieve JSON data. The application allows dynamic string manipulation within a predefined JSON model and stores the manipulated JSON models in a database.
- Java 11 or later
- Maven 3.6.3 or later
- A running instance of MySQL
-
Clone the repository:
git clone https://github.com/your-repo/json-manipulation-api.git cd json-manipulation-api
-
Configure the database: Update the
application.yml
file with your database configuration:spring: application: name: StringManipulation datasource: url: jdbc:mysql://localhost:3306/SMDb driverClassName: com.mysql.cj.jdbc.Driver username: root password: root h2: console: enabled: true jpa: database-platform: org.hibernate.dialect.MySQL8Dialect hibernate: ddl-auto: update springdoc: swagger-ui: path: /swagger-ui.html api-docs: path: /api-docs
-
Build and run the application:
mvn clean install mvn spring-boot:run
- URL:
/api/manipulate
- Method: POST
- Parameters:
input
(String): A string containing key-value pairs separated by:::
, and pairs separated by commas. Example:New:::NewDocument,Open:::OpenDocument
- Response:
200 OK
: Returns the modified JSON model.500 Internal Server Error
: Returns an error message if processing fails.
Example Request:
curl -X POST "http://localhost:8080/api/manipulate?input=New:::NewDocument,Open:::OpenDocument"
Example Response:
{
"menu": {
"id": "file",
"value": "File",
"popup": {
"menuitem": [
{"value": "NewDocument", "onclick": "CreateDoc()"},
{"value": "OpenDocument", "onclick": "OpenDoc()"},
{"value": "Save", "onclick": "SaveDoc()"}
]
}
}
}
- URL:
/api/list
- Method: GET
- Response:
200 OK
: Returns a list of all stored JSON models.500 Internal Server Error
: Returns an error message if retrieval fails.
Example Request:
curl -X GET "http://localhost:8080/api/list"
Example Response:
[
{
"id": 1,
"jsonModel": "{\"menu\": {\"id\": \"file\",\"value\": \"File\",\"popup\": {\"menuitem\": [{\"value\": \"NewDocument\", \"onclick\": \"CreateDoc()\"},{\"value\": \"OpenDocument\", \"onclick\": \"OpenDoc()\"},{\"value\": \"Save\", \"onclick\": \"SaveDoc()\"}]}}}"
}
]
Postman can be used to test the API endpoints. Import the provided collection and run the tests.
The application uses Swagger to document the API. Once the application is running, you can access the API documentation at:
http://localhost:8080/swagger-ui.html
This `README.md` now includes the `application.yml` configuration for setting up the database connection and Swagger documentation paths.