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

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

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

Technologies

– Kotlin SpringBoot
– PostgreSQL
– Postman Rest-Client

Practices

Project Structure ->

kotlin-springboot-xml-restapi-postgresql---project-structure

Create SpringBoot project

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

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

Model

– We use @JacksonXmlRootElement & @JacksonXmlProperty to create Customer.kt 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.kt 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.kt ->

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 Kotlin SpringBoot application & start PostgreSQL database.

-> Make post requests:

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

kotlin-springboot-xml-restapi-postgresql---save-customers-records

-> Get customers:

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

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

-> Put a customer:

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

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

– Delete a customer:

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

kotlin-springboot-xml-restapi-postgresql---mysql-delete-customers

Sourcecode

KotlinSpringBootXMLRestAPI

By grokonez | January 24, 2019.



Related Posts


Got Something To Say:

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

*