Spring Boot – RESTful Web Service with POST Request in JSON Example

In the previous articles I didn’t get a chance to use the POST request in the examples, but this is very important. In this article I am going to show you how to create a Spring Boot REST service with POST request in JSON format with a simple example.

As Spring Boot by default supports JSONΒ request and responses, we no need to add any dependencies. A simple annotation called @RequestBody will do the trick for us πŸ˜‰


    xmlns:xsi="" xsi:schemaLocation="">


import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

public class SpringBootApp {
    public static void main(String[] args) {, args);


package com.java4s.model;

public class Customer {

    private int custNo;
    private String name;
    private String country;

    public Customer() {


    public Customer(int custNumber, String name, String country) {
        this.custNo = custNumber; = name; = country;

    public int getCustNo() {
        return custNo;

    public void setCustNo(int custNo) {
        this.custNo = custNo;

    public String getName() {
        return name;

    public void setName(String name) { = name;

    public String getCountry() {
        return country;

    public void setCountry(String country) { = country;


import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import com.java4s.model.Customer;

public class SpringJava4sController {

    @PostMapping(path = "/save-cust-info")
    public String customerInformation(@RequestBody Customer cust) {

        /* You can write your DAO logic here.
         * For time being I am printing the customer data just to show the POST call is working.

        return "Customer information saved successfully ::." + cust.getCustNo() + " " + cust.getName() + " " + cust.getCountry();



Run the application and open the URL in Postman


	"custNo" : 100,
	"name" : "Google",
	"country": "United States"



​ ​​

You Might Also Like

  ::. About the Author .::

- Java/J2EE Full Stack Developer
Founder of Java4s - Get It Yourself, A popular Java/J2EE Programming Blog, Love Java and UI frameworks.
You can sign-up for the Email Newsletter for your daily dose of Java tutorials.


3 Responses to “Spring Boot – RESTful Web Service with POST Request in JSON Example”
  1. Manikandan says:

    Its nice….

  2. ganapathi says:

    Customer information saved successfully ::.0 Google United States

    it shows like that ,always shows zero.why?


By posting your answer, you agree to our comments policy.
Most Recent Posts from Top Categories
Spring Boot Hibernate Spring
Contact | About Us | Privacy Policy | Advertise With Us

© 2010 - 2018 Java4s - Get It Yourself.
The content is copyrighted to Sivateja Kandula and may not be reproduced on other websites.