helloworld
RESTful 프로젝트? 본문
글쓰는게 너무 어렵다
restful 에 대한 이해가 너무 부족한거 같아 인프런에서 강의를 끊고 보았다.
우선 rest란 내가 이해한 바로는 url 에서 도메인에 대한 이해를 바로 할 수있고 직관적으로 표현하여 사용자나 개발자가 봐도 이해할 수 있는 느낌인 것 같다.
REST는 REpresentantional State Transfer 의 약자로 resource의 representantional에 의한 상태를 전달하고 HTTP 의 method를 통해 resource를 처리한다.
-- 자원의 상태를 전달하기 위한 ~..
HTTP method는 GET,POST,PUT,DELETE가 있다.
GET은 read 읽고 ex) localhost:8080/user/1 - > 유저목록의 1번 번호를 가져와라
POST는 create 생성 ex)localhost:8080/user/100 -> 유저목록에 100번 번호 추가
PUT은 update 덮어쓰기
DELETE 삭제
를 의미한다.
내가 생각한게 맞겠지
스프링이나 스프링부트에서 restful 프로젝트를 만들때에는
컨트롤러.java 파일에 @Controller 어노테이션이아닌 @RestController를 사용해야한다.
@RestController
public class HelloController {
//GET
// /hello-world -> End-point
// @RequestMapping(method=RequestMethod.GET, path= "/hello-world")
@GetMapping(path = "/hello-world")
public String helloWorld() {
return "Hello World";
}
//alt + enter
@GetMapping(path = "/hello-world-bean")
public HelloWorldBean helloWorldBean() {
return new HelloWorldBean("Hello World");
}
@GetMapping(path = "/hello-world-bean/path-variable/{name}")
public HelloWorldBean helloWorldBean(@PathVariable String name) {
// %s -> 가변데이터가 올 수 있다.. %s안에 name이라는 값이 들어감
//ex -> name : 우병걸이면 hello world, 우병걸
return new HelloWorldBean(String.format("Hello World, %s", name));
}
}
public class HelloController {
//GET
// /hello-world -> End-point
// @RequestMapping(method=RequestMethod.GET, path= "/hello-world")
@GetMapping(path = "/hello-world")
public String helloWorld() {
return "Hello World";
}
//alt + enter
@GetMapping(path = "/hello-world-bean")
public HelloWorldBean helloWorldBean() {
return new HelloWorldBean("Hello World");
}
@GetMapping(path = "/hello-world-bean/path-variable/{name}")
public HelloWorldBean helloWorldBean(@PathVariable String name) {
// %s -> 가변데이터가 올 수 있다.. %s안에 name이라는 값이 들어감
//ex -> name : 우병걸이면 hello world, 우병걸
return new HelloWorldBean(String.format("Hello World, %s", name));
}
}
@RequestMapping 은 옛날 방식이라고 한다..
프로젝트 실행 시킨후 (난 oracle을 사용중이라 포트번호를 9090으로 수정했다)
localhost:9090/hello-world-bean 이라고 url에 치면

JSON형태로 값을 출력한다 ..
'restful' 카테고리의 다른 글
| DELETE 기능 (0) | 2023.08.13 |
|---|---|
| Exception 처리 심화과정 .. (0) | 2023.08.13 |
| Exception 처리 (0) | 2023.08.13 |
| rest PostMapping 2 (0) | 2023.08.13 |
| restful PostMapping (0) | 2023.08.13 |