[Spring] Postman 사용 - POST

4799 단어 SpringSpring

POST를 사용하기 위한 사전 환경 설정

API key값을 받아와야 POST방식을 사용할 수 있다.

+ 클릭으로 collection 추가 후 ,Request name : Submit an order, save 클릭

마찬가지로 Request name : API Auth 도 생성


https://github.com/vdespa/introduction-to-postman-course/blob/main/simple-books-api.md

API Auth에서 GET 말고 POST로 지정

{{baseUrl}}/api-clients 입력 후, Body에서 raw 클릭

text대신 JSON 클릭

{
    "clientName" : "Dingdoooo",
    "clientEmail" : "[email protected]"
}

Body부분에 코드 clientName, clientEmail 더미 데이터 집어 넣은 후 Send 클릭

Response부분에 accessToken이 생성, Status : 201 Created 인 것도 확인 가능

(API에서 POST방식을 사용할 수 있도록 토큰 값을 받는다)

Collections - Simple books APIEdit 클릭

Variables클릭

Variable = accessToken , Initial Value = 토큰 값 넣기

✨ 주의 사항 : ctrl + s 로 variable 저장해야함 !!! ✨


🥫 Submit an order collection

Body의 none을 raw로 선택

text를 JSON 선택

bookId, customerName 데이터 입력


Authorization 추가하기

Params 옆의 Authorization 클릭

Bearer Token 클릭

{{accessToekn}} 입력

Headers의 hidden 클릭

Authorization이 제대로 등록되었다.

send 클릭하면, created, ordered가 생성된다


Get All orders collection


collection +추가 후 ,Save as 클릭

Request name : Get All orders 입력 후 Save

API 접근을 위해 Authorization을 추가해야한다.

Params 옆의 Auth 클릭, Type은 Bearer Token 클릭


Token에 {{accessToken}} 입력

{{baseUrl}}/orders 입력 후 , Send 클릭

지금까지 Order한 모든 데이터가 출력된다.


Update an order collection


{{baseUrl}}/orders/:orderId 입력

Get an order에서 id : COE2t0PHBVhWUPm1VF0Sw 하나 가져오기

orderId VALUE 값에 집어넣기

GET에서 PATCH로 변경한 뒤 , Send 클릭

response의 Body에는 아무것도 뜨지 않는다.


Update 확인하기

Get All orders에서 Send 클릭했을 때,
id가 COE2t0PHBVhWUPm1VF0SwcustomerName이 Joo에서 Jinjoo로 변경되었다.

좋은 웹페이지 즐겨찾기