The cURL annotation helps you generate a Postman collection directly from your Spring Rest API code. By applying this annotation to your controller methods, you can automatically create detailed entries for each endpoint in your API.
Maven
Add the following dependency to your pom.xml file:
<pom>
<dependency>
<groupId>io.bytescraft</groupId>
<artifactId>cURL</artifactId>
<version>0.0.3</version>
</dependency>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.plugin.version}</version>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>io.bytescraft</groupId>
<artifactId>cURL</artifactId>
<version>0.0.3</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
</pom>Gradle
Add the following dependency to your build.gradle file:
implementation 'io.bytescraft:cURL:0.0.3'
annotationProcessor 'io.bytescraft:cURL:0.0.3'Use the cURL annotation on your controller methods to define the details for the Postman collection.
Example:
@RestController@RequestMapping("/message")
publicclassMessageController {
@cURL(name = "Get Message", folder = "/v1")
@GetMapping(value = "/{id}" , produces = "application/json")
publicResponseDTOgetMessage(@PathVariable("id") Longid){
ResponseDTOresponseDTO = newResponseDTO();
responseDTO.setMessage("Hello World" + id);
returnresponseDTO;
}
@cURL(name = "Post Message")
@PostMapping(consumes = "application/json", headers = "Accept=application/json")
publicResponseDTOpostMessage(@Valid@RequestBodyRequestDTOrequestDTO) {
ResponseDTOresponseDTO = newResponseDTO();
responseDTO.setMessage("Hello World " + requestDTO.getName());
returnresponseDTO;
}
@cURL@PutMapping(value = "/{id}" , produces = "application/json", consumes = "application/json")
publicResponseDTOputMessage(@PathVariable("id") Longid, @RequestBody@ValidRequestDTOrequestDTO) {
ResponseDTOresponseDTO = newResponseDTO();
responseDTO.setMessage("Hello World " + requestDTO.getName());
returnresponseDTO;
}
@cURL@DeleteMapping(value = "/{id}" , produces = "application/json")
publicResponseDTOdeleteMessage(@PathVariable("id") Longid) {
ResponseDTOresponseDTO = newResponseDTO();
responseDTO.setMessage("Hello World");
returnresponseDTO;
}
@cURL@GetMapping(value = "/filter" , produces = "application/json")
publicResponseDTOfilterMessages(@RequestParam(name = "query") Stringquery, @RequestParam(name = "page", required = false) intpage, @RequestParam(name = "size", required = false) intsize) {
ResponseDTOresponseDTO = newResponseDTO();
responseDTO.setMessage("Hello World");
returnresponseDTO;
}
}Create a cURL.yaml file at the src folder level in your Java project. This configuration file supports the following properties:
- collection.name: The name of the generated collection.
- collection.description: A description for the generated collection.
Example cURL.yaml file:
collection:
name: cURLdescription: cURL is a command-line tool for getting or sending data including files using URL syntax.clients:
- POSTMAN
- THUNDER_CLIENTvar:
HOST: https://www.example.comPORT: 443ID: 40postman:
collection:
pre-request: | pm.request.headers.add({key: 'userType',value: 'MANAGER'});post-response: | pm.collectionVariables.set("variable_key", "variable_value");Your project structure should look like this:
my-java-project/
├── src/
│ ├── main/
│ │ ├── java/
│ │ └── resources/
├── cURL.yaml
├── pom.xml (for Maven projects)
└── build.gradle (for Gradle projects)Once your methods are annotated, build your project to generate a Postman collection. The specifics of this process will depend on the integration details of the cURL annotation, which typically involves running a Maven or Gradle task to process the annotations and output the Postman collection.
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Please submit a pull request or open an issue to discuss your changes.
For any issues or questions, please open an issue in this repository.