Deep_Dev
article thumbnail

์Šคํ”„๋ง ๋ถ€ํŠธ์˜ ๊ฒฝ์šฐ ์Šคํ”„๋ง๊ณผ ๋น„๊ตํ•˜์—ฌ ์•„์ฃผ ์‹ฌํ”Œํ•˜๊ฒŒ API์„œ๋ฒ„๋ฅผ ๊ตฌ์ถ•ํ•ด๋ณผ ์ˆ˜ ์žˆ๋‹ค.

 

๋‹ค๋งŒ ์•„๋ž˜์™€ ๊ฐ™์€ ์กฐ๊ฑด์— ๋”ฐ๋ผ ํ”„๋กœ์ ํŠธ์˜ ์–‘์ด๋‚˜ ๋ณต์žก๋„๊ฐ€ ๋‹ฌ๋ผ์ง„๋‹ค.

 

 

 
1. ์›์ฒœ ๋ฐ์ดํ„ฐ์˜ ํ˜•ํƒœ : RDBMS, NoSQL, Hadoop ๋“ฑ

    : ์–ด๋– ํ•œ ๊ณณ์—์„œ ์›์ฒœ ๋ฐ์ดํ„ฐ ์ •๋ณด๋ฅผ ๊ฐ€์ ธ์™€์„œ ํด๋ผ์ด์–ธํŠธ์— ๋ณด๋‚ด์ค„์ง€ ์ •ํ•ด์•ผ ํ•œ๋‹ค.

2. ์บ์‹œ ๋ฐ์ดํ„ฐ ์‚ฌ์šฉ ์—ฌ๋ถ€
    : ํด๋ผ์ด์–ธํŠธ์˜ ์ •๋ณด ์š”์ฒญ์„ ๋ฐ›์„๋•Œ๋งˆ๋‹ค ๊ณ„์† ์›์ฒœ๋ฐ์ดํ„ฐ๋ฅผ ์ƒˆ๋กญ๊ฒŒ ์ฝ์–ด๋“ค์ผ ๊ฒƒ์ธ์ง€, ๊ทธ๋ ‡๊ฒŒ ๊ณ„์† Readํ•˜์—ฌ ์‹ค์‹œ๊ฐ„์œผ๋กœ ์ตœ์‹ ์ •๋ณด๋ฅผ ๋ฆฌํ„ดํ•  ํ•„์š”๊ฐ€ ์—†๋Š”์ง€ ( ์˜ˆ๋ฅผ๋“ค์–ด 1์‹œ๊ฐ„ ์ฃผ๊ธฐ๋กœ๋งŒ ๊ฐฑ์‹ ์ •๋ณด๋ฅผ ๋ฆฌํ„ดํ•ด๋„ ๋œ๋‹ค๋“ ๊ฐ€ ํ•˜๋Š” )๋ฅผ ์ •ํ•ด์•ผ ํ•œ๋‹ค.

3. HTTP ๋ฉ”์†Œ๋“œ ๋ฐฉ์‹ : restful์ธ๊ฐ€ ์•„๋‹Œ๊ฐ€
    : API์ฃผ์†Œ๋ฅผ ์กฐ๊ธˆ ๋” ๋ช…ํ™•ํ•˜๊ณ  ์ •ํ˜•ํ™”ํ•˜์—ฌ ์ฒ˜๋ฆฌํ•˜๋Š”๊ฒŒ ๋ชฉ์ ์„ ๋‘” restful api๋ฐฉ์‹์„ ์ตœ๊ทผ์—๋Š” ์„ ํ˜ธํ•œ๋‹ค.

4. ์ ‘๊ทผ ์ œ์–ด : ๋ณด์•ˆ์ฒ˜๋ฆฌ ๋ฐ ์‚ฌ์šฉ์ž ์ œ์–ด
    : ์ต๋ช…์˜ ์‚ฌ์šฉ์ž๋„ ์ ‘๊ทผ์ด ๊ฐ€๋Šฅํ•˜๊ฒŒ ํ•  ๊ฒƒ์ธ๊ฐ€ ์•„๋‹Œ๊ฐ€์— ๋”ฐ๋ผ ๋ณด์•ˆ ์ •์ฑ… ๋ฐ ์‚ฌ์šฉ์ž ๊ตฌ๋ถ„ ์ฒ˜๋ฆฌ๋ฅผ ํ•ด์•ผํ•œ๋‹ค.

 

 

ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ

์ธํ…”๋ฆฌ์ œ์ด๋ฅผ ์‹คํ–‰ํ•˜์—ฌ 'Create New Project' - ์™ผ์ชฝ์—์„œ 'Maven' ์„ ํƒํ›„ 'Name'์ž‘์„ฑ ํ›„ Next

 

 

 

 

 

ํ”„๋กœ์ ํŠธ ๊ธฐ๋ณธ ๊ตฌ์„ฑํ™•์ธ ๋ฐ ์ˆ˜์ •

ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ ํ›„ ๋ฐ”๋กœ ๋ณด์ด๋Š” pom.xml์„ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ˆ˜์ • (parent, dependencies, build)ํ•˜์—ฌ ์Šคํ”„๋ง ๋ถ€ํŠธ ์˜์กด์„ฑ ์ถ”๊ฐ€

<?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>

    <groupId>com.sentilab</groupId>
    <artifactId>sentilabHadoop</artifactId>
    <version>1.0-SNAPSHOT</version>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.7.RELEASE</version>
    </parent>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

 

์ดํ›„ ์˜ค๋ฅธ์ชฝ ์ƒ๋‹จ์— ๋ณด์ด๋Š” refresh ํด๋ฆญํ•˜์—ฌ ์ ์šฉ

 

 

< ๋‹ค์Œ๊ณผ ๊ฐ™์ด ํ”„๋กœ์ ํŠธ ๊ตฌ์กฐ ์ƒ์„ฑ >

1) src-main-java ์—์„œ package ์ƒ์„ฑ 

2) ์ƒ์„ฑํ•œ package ๋‚ด์— startApp , ApiController : JAVA CLASS ์ƒ์„ฑ

 

 

 

 

startApp Class ์ˆ˜์ • : SpringBoot ํ–ฅ์œผ๋กœ ๋ณ€๊ฒฝ

package com.restapi;

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

@SpringBootApplication
public class starApp {

    public static void main(String[] args) {
        // SpringApplication์„ ์‹คํ–‰ํ•˜๊ฒ ๋‹ค.
        SpringApplication.run(starApp.class, args);
    }
}
  • ํ•ต์‹ฌ
    • @SpringBootApplication ์–ด๋…ธํ…Œ์ด์…˜ ์ถ”๊ฐ€
    • main ํด๋ž˜์Šค์— SpringApplication.run ์ถ”๊ฐ€

 

 

 

๐Ÿ’ก ์‹คํ–‰ ํƒ€๊ฒŸ ๋งŒ๋“ค๊ธฐ

 

1. ์ƒ๋‹จ 'Add Configuration' ํด๋ฆญ

 

2. ํŒ์—… ์ขŒ์ธก +๋ฒ„ํŠผ ํด๋ฆญํ•˜์—ฌ SpringBoot ์„ ํƒ ( ์ธํ…”๋ฆฌ์ œ์ด ์ปค๋ฎค๋‹ˆํ‹ฐ ๋ฒ„์ „์—์„œ๋Š” ์Šคํ”„๋ง๋ถ€ํŠธ ๋ณด์ด์ง€ ์•Š์Œ )

 

3. ์ƒ๋‹จ Name ๋ณ€๊ฒฝ ํ›„, ์ค‘์•™ Build and run ํƒญ์˜ 

์‚ฌ์ง„์ƒ์— com.restapi.startApp ์นธ์˜ ๋งจ ์˜ค๋ฅธ์ชฝ $ ์„ ํƒํ•˜์—ฌ ์‚ฌ์ง„์ฒ˜๋Ÿผ startApp ์„ ํƒ

 

 

 

4. ๋นŒ๋“œ๋ฅผ ์‹คํ–‰ํ•˜์—ฌ ๊ฒฐ๊ณผ ํ™•์ธ

 

 

 

๐Ÿ’ก Rest Api ์ ์šฉ

1. ์ƒ์„ฑํ–ˆ๋˜ ApiController ํด๋ž˜์Šค์— ๋‹ค์Œ๊ณผ ๊ฐ™์ด ๊ธฐ๋ณธ์ ์ธ APIํ˜ธ์ถœ ๋ฆฌํ„ด ํด๋ž˜์Šค๋ฅผ ์ƒ์„ฑํ•˜๊ณ  ์•ฑ ์žฌ์‹œ์ž‘

package com.restapi;

import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ApiController {

    @RequestMapping(value="/api/test",method = RequestMethod.GET)
    @ResponseStatus(value= HttpStatus.OK)
    public String getApiTest(){
        return "{\"result\":\"test\"}"; // json type ๋ฐ˜ํ™˜
    // /api/test ์ฃผ์†Œ๋ฅผ ํ˜ธ์ถœํ•˜๋ฉด -> return์— ์žˆ๋Š” ๊ฐ’์„ ๋Œ๋ ค์ฃผ๊ฒ ๋‹ค.
    }
    // localhost:8080/api/test
}

 

 

2. localhost:8080/api/test ์ ‘์†ํ•˜์—ฌ ์ •์ƒ์ ์œผ๋กœ ๊ฒฐ๊ณผ ๋ฐ˜ํ™˜ํ•ด์ฃผ๋Š” ํ™•์ธ