[인프런 워밍업 클럽 스터디] 1일차 - 서버 개발을 위한 환경설정

image

 

Section 1. 생애 최초 API 만들기

[목표]

  1. 스프링 프로젝트를 설정해 시작하고 실행할 수 있다.

  2. 서버란 무엇인지, 네트워크와 HTTP, API는 무엇인지, JSON은 무엇인지 등 서버 개발에 필요한 다양한 개념을 이해한다.

  3. 스프링 부트를 이용해 간단한 GET API, POST API를 만들 수 있다.


     

[이론 총정리]

  1. (웹을 통한)컴퓨터 간의 통신은 HTTP라는 표준화된 방식이 있다.

  2. HTTP 요청은 HTTP Method (GET, POST)와 Path (/portion)가 핵심이다.

  3. 요청에서 데이터를 전달하기 위한 2가지 방법은 쿼리와 바디이다.

  4. HTTP 응답은 상태코드가 핵심이다.

  5. 클라이언트와 서버는 HTTP를 주고 받으며 기능을 동작하는데 이때 정해진 규칙을 API라고 한다.

 

[사용 어노테이션]

@RestController : 주어진 Class를 Controller로 등록한다. API의 진입 지점.

@GetMapping("/add") : 아래의 함수를 HTTP Method가 GET이고 HTTP Path가 /add인 API로 지정한다.

@RequestParam : 주어지는 쿼리를 함수 파라미터에 넣는다.

 


[질문]

  • 어노테이션을 사용하는 이유 (효과) 는 무엇일까?

     

Annotations in Java

Annotations are used to provide supplemental information about a program.

Annotations start with ‘@’.

  • Annotations do not change the action of a compiled program.

  • Annotations help to associate metadata (information) to the program elements i.e. instance variables, constructors, methods, classes, etc.

  • Annotations are not pure comments as they can change the way a program is treated by the compiler.

  • Annotations basically are used to provide additional information, so could be an alternative to XML and Java marker interfaces.

 

  • 나만의 어노테이션은 어떻게 만들 수 있을까?

How to Create Your Own Annotations in Java?

Annotations are a form of metadata that provide information about the program but are not a part of the program itself. An Annotation does not affect the operation of the code they Annotate. 

Now let us go through different types of java annotations present that are listed as follows:

  1. Predefined annotations.: @Deprecated, @Override, @SuppressWarnings, @SafeVarargs, @FunctionalInterface.

  2. Meta-annotations: @Retention, @Documented, @Target, @Inherited, @Repeatable.

  3. Custom annotations: These are defined by the user. (We will be learning to create custom annotations in this module).

Geek, now you must be wondering how can we create our own java annotations, for that refer to simple steps sequentially as follows:

  1. To create your own Java Annotation you must use @interface Annotation_name, this will create a new Java Annotation for you.

  2. The @interface will describe the new annotation type declaration.

  3. After giving a name to your Annotation, you will need to create a block of statements inside which you may declare some variables.

 

출처 1. https://www.geeksforgeeks.org/annotations-in-java/

출처 2. https://www.geeksforgeeks.org/how-to-create-your-own-annotations-in-java/

 

댓글을 작성해보세요.