What is an API?
Application Programming Interface (API) is a software interface that allows two applications to interact with each other without any user intervention. API is a collection of software functions and procedures. In simple terms, API means a software code that can be accessed or executed. API is defined as a code that helps two different software’s to communicate and exchange data with each other.
SpringBoot :
Spring Boot is an open source Java-based framework used to create a micro Service. It is developed by Pivotal Team and is used to build stand-alone and production ready spring applications.
A simple API using SpringBoot:
Step 1. Firstly we will create java spring boot project using website . I am selecting maven project with java and spring boot2.1.3 . After that Fill Group , Artifact details and click generate project
.
Step 2: After Click Generate project button it will download java spring boot project for you. Now you extract this zip and import in eclipse . After import java spring boot project in eclipse , application structure such as.
HelloWorldApplication.java
package com.jp.helloWorld;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class HelloWorldApplication {
public static void main(String[] args) {
SpringApplication.run(HelloWorldApplication.class, args);
}
}
Now we will create one rest controller which consume request and produce response for us.
HelloController.java
package com.jp.helloWorld.controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloController {
@GetMapping("/app")
public String getApplicationName(){
return "Application api call succsfully";
}
}
pom.xml
<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.1.3.RELEASE</version><relativePath/> <!-- lookup parent from repository --></parent><groupId>com.jp</groupId><artifactId>helloWorld</artifactId><version>0.0.1-SNAPSHOT</version><name>helloWorld</name><description>Demo project for Spring Boot</description><properties><java.version>1.8</java.version></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-devtools</artifactId><scope>runtime</scope></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency></dependencies><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build></project>
Now run application by run HelloWorldApplication.java as java project and open url in your browser or any rest client http://localhost:8080/app , you will got response of your api as.
How does CodersArts helps you ?
CodersArts provide :
Spring boot assignment Help
Help in development Projects
Mentorship from Experts Live 1:1 session
Course and Project completions
CourseWork help
Hozzászólások