Skip to content

Sudarshan-Gowda/Spring-Boot-Rest-Template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Spring-Boot-Rest-Template

To consume the exposed Restfull web services in Spring Application, Rest Template is also one of the popular library or helper class available in spring framework. This example is ellustrated with how to consume the restfull api by using Rest Template class.

Rest Template class will provide many helper methods to consume the Restfull webservices like

  • getForEntity
  • postForEntity
  • put
  • delete


If you dont want to use different methods for each of the API means, you can go for the single function exchange and pass the specific Http Method type to consume API's.


Before using the Rest Client , you need to initailize, that can be done in any of your class as below,

You can then access application by using Url here: http://localhost:8080/

In case you find a bug/suggested improvement for Spring Restfull Webservices

Our issue tracker is available here: https://github.com/Sudarshan-Gowda/Spring-Boot-Rest-Template/issues

Working with this project in Spring Tool Suite or Eclipse

prerequisites

The following items should be installed in your system:

  • STS - 3.0 Plus
  • Postman or Any Rest API Testing tool

Steps:

  1. Download this Project and do maven import.
git clone https://github.com/Sudarshan-Gowda/Spring-Boot-Rest-Template.git
  1. To Import the Praject Using STS or Eclipse
File -> Import -> Maven -> Existing Maven project

Looking for something in particular?

Spring Boot Configuration Class or Java property files
Main Class - Expose ExposeController
Main Class - Consume ConsumeController

Steps to test the application:

  1. Run the Application by using CLI,
    mvn spring-boot:run
  2. Test the API by using Rest API Testing tool.

### Find the exposed restfull APIS as below

Place the below urls and select appropicate Http Methods to test the APIs


a. To get the list of employees
http://localhost:8080/employees

b. To fetch the employee by id
http://localhost:8080/employees/1

c. To create the employee record
http://localhost:8080/employees
{ "empId": 1, "empName": "Sudarshan", "empDept": "PD", "empSalary": 1234567 }

d. To update the employee record
http://localhost:8080/employees
{ "empId": 1, "empName": "Sudarshan", "empDept": "PD", "empSalary": 1234567 }

e. To delete the employee record
http://localhost:8080/template/employees/1

Find the Consuming restfull APIS as below

a. To get the list of employees
http://localhost:8080/template/employees

b. To fetch the employee by id
http://localhost:8080/template/employees/1

c. To create the employee record
http://localhost:8080/template/employees
{ "empId": 1, "empName": "Sudarshan", "empDept": "PD", "empSalary": 1234567 }

d. To update the employee record
http://localhost:8080/template/employees
{ "empId": 1, "empName": "Sudarshan", "empDept": "PD", "empSalary": 1234567 }

e. To delete the employee record
http://localhost:8080/template/employees/1

Contributing

The issue tracker is the preferred channel for bug reports, features requests and submitting pull requests.

For pull requests, editor preferences are available in the editor config for easy use in common text editors.

About

Consuming Rest API using Spring Rest Template

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages