


version은 개발자의 API 버전 의미 (1.0.0)
{JSON} Placeholder
https://jsonplaceholder.typicode.com/

'https://jsonplaceholder.typicode.com/todos/1'

openapi: 3.0.0
info:
version: 1.0.0
title: API_Example
description: Swagger 실습을 위한 API Example
servers:
# Added by API Auto Mocking Plugin
- description: SwaggerHub API Auto Mocking
url: https://virtserver.swaggerhub.com/HANWLDN76_1/API_Example/1.0.0
- description: JSON Placeholder API
url : https://jsonplaceholder.typicode.com
paths:
/todos/{id}:
get:
summary: id값에 따른 사용자의 할 일 목록 반환
parameters:
- name: id
in: path
required: true
description: The ID of the user to return
schema:
type: integer
responses:
'200':
description: OK
content:
application/json:
schema:
type: object
properties:
userId:
type: integer
id:
type: integer
title:
type: string
completed:
type: boolean
설명
- description: JSON Placeholder API
url : https://jsonplaceholder.typicode.com
paths:
/todos/{id}:
get:
summary: id값에 따른 사용자의 할 일 목록 반환
parameters:
- name: id
in: path
required: true
description: The ID of the user to return
schema:
type: integer
in: pathrequired: truedescription: The ID of the user to returnschema:type: integer responses:
'200':
description: OK
content:
application/json:
schema:
type: object
responses:'200':content:application/json:schema:type: object properties:
userId:
type: integer
id:
type: integer
title:
type: string
completed:
type: boolean
properties:{
"userId": 1,
"id": 1,
"title": "delectus aut autem",
"completed": false
}
이렇게 까지하면 API 명세 완료
save하면 API가 적용되고, API 명세서를 새로고침하면 작업한 내용이 반영되어 있음

/todos/{id}라는 path에 어떠한 데이터 (ex. id=7)를 넣어서 보내게 되면 결과가 반영되어서 나옴 (200 응답 코드)




Response Body가 서버가 응답한 데이터를 그대로 보여줌.
/todos:
get:
summary: 모든 사용자의 할 일 목록 반환
responses:
'200':
description: OK
content:
application/json:
schema:
type: array
items:
type: object
properties:
userId:
type: integer
id:
type: integer
title:
type: string
completed:
type: boolean
설명
schema:
type: array
items:
type: object
서버 개발자와 클라이언트 개발자는 이 문서 하나만 보고 개발
하나의 API 문서에는 하나의 서버를 권장!
추가 정리...!
in: pathin: queryPath Parameter
경로를 변수로서 사용하는 방법
/users/123 => 아이디가 123인 사용자를 가져옴
Query Parameter
? 이후에 변수 선언을 통해 사용하는 방법
/users?id=123 => 아이디가 123인 사용자를 가져옴
parameters:
- name: id
in: path
required: true
description: The ID of the user to return
schema:
type: integer
전체 사용자의 할 일 목록 데이터 :
개별 사용자의 할 일 목록 데이터 :


url에서 특정한 조건을 주고싶을 때 사용하는 파라미터 유형
같은 API를 호출한다고 해도, 서로 다른 조건으로 나열하는 것이 필요한 상황에 사용
URL 끝 물음표(?) 뒤에 나타나며, and 기호(&)로 구분된 이름=값 쌍으로 구성
HTTP의 [GET], [DELETE] 요청에서만 사용
유일 값을 식별하기 위한 용도가 아닌 옵션을 줄 때 사용
데이터 필터링
데이터 정렬
데이터 수 조절 (페이지네이션)
검색 등
같은 신발 목록 데이터를 호출 하는데, 신상품 순, 사이즈가 230인 데이터만 따로, 사이즈가 250인 제품 따로, 낮은 가격순으로 데이터를 호출하는 API를 매번 새로 생성하는 것은 비효율적
따라서 필요한 조건을 요청에 따라 선택적으로 처리할 수 있는 통일된 API를 구성할 때 사용
parameters:
- name: q
in: query
schema:
type: string
필터링
completed가 false인 할 일 목록

completed가 false이고, id가 5인 할 일 목록

정렬
데이터 수 조절
아래와 같은 요청을 보내면, 전체 데이터 가운데 0번부터 100번까지만 호출하게 됩니다.
검색
(+)
Query parameter을 이용해 생성된 위 4가지 API는 기본적으로 [GET] /todos 와 동일한 API를 호출하는 것
따라서 API는 한가지이고, query string을 변수로 받아서 각각의 조건마다 필요한 데이터를 전송
위 변수들을 request body 에 넣고 요청할 수 있지 않을까? 라고 생각할 수 있지만, 데이터를 표현하는 HTTP method는 [GET] 이고, GET method에서는 request body를 사용하지 않는 것이 권장
따라서 GET method를 호출하면서 동시에 정보를 전달할 때에는 query parameter를 이용