SpringBoot XML RestAPIs + PostgreSQL – Post/Get/Put/Delete Requests Example

springboot-xml-restapi-postgresql---feature-image

In the tutorial, Grokonez show you how to create SpringBoot XML RestAPIs and PostgreSQL with Post/Get/Put/Delete requests using jaxb-api & jackson-dataformat-xml

Related posts:
How to use Spring JPA with PostgreSQL | Spring Boot

Technologies

– SpringBoot
– PostgreSQL
– Postman Rest-Client

Practices

Project Structure ->

springboot-xml-restapi-postgresql---spring-boot-project

Create SpringBoot project

– We use SpringToolSuite to create a SpringBoot project with below dependencies:

– The jackson-dataformat-xml adds Jackson XML serializer and deserializer.

Model

– We use @JacksonXmlRootElement & @JacksonXmlProperty to create Customer.java model:

  • @JacksonXmlProperty is used to set an attribute of the element in the XML output.
  • @JacksonXmlRootElement is used to set the name for the XML output root element.

– Create an Customers.java helper class:

-> We use @JacksonXmlProperty & @JacksonXmlElementWrapper annotations to set a list of Customer to be elements of Customers element in XML output.

JPA Repository

– Create JPA repository CustomerRepository.java ->

Controller RestAPIs

– We create 4 RestAPIs with Post/Get/Put/Delete XML request-mapping:

-> With MediaType.APPLICATION_XML_VALUE, Spring uses a message converter to produces XML data.

Application configuration

– Open file application.properties, add configuration:

Run & Check Results

– Run SpringBoot application & start PostgreSQL database.

-> Make post requests:

springboot-xml-restapi-postgresql---post-request

springboot-xml-restapi-postgresql---post-request-postgresql-records

-> Get customers:

springboot-xml-restapi-postgresql---get-request-by-id

springboot-xml-restapi-postgresql---get-all-customers

-> Put a customer:

springboot-xml-restapi-postgresql---put-a-customer

springboot-xml-restapi-postgresql---put-request-postgresql-records

– Delete a customer:

springboot-xml-restapi-postgresql---delete-request

springboot-xml-restapi-postgresql---delete-postgresql-records

Sourcecode

SpringBootXMLRestAPI

By grokonez | January 17, 2019.



Related Posts


Got Something To Say:

Your email address will not be published. Required fields are marked *

*