Jieunny์˜ ๋ธ”๋กœ๊ทธ

S2) Unit 8. [HTTP/๋„คํŠธ์›Œํฌ] Postman ๋ณธ๋ฌธ

CodeStates/learning contents

S2) Unit 8. [HTTP/๋„คํŠธ์›Œํฌ] Postman

Jieunny 2023. 2. 1. 17:00

๐Ÿ“ฃ  Postman

โœ”๏ธ ๋งค๋ฒˆ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•˜๋Š” ๊ฒƒ ๋Œ€์‹ ์—, HTTP ์š”์ฒญ์„ ํ…Œ์ŠคํŠธํ•  ์ˆ˜ ์žˆ๋Š” HTTP API ํ…Œ์ŠคํŠธ ๋„๊ตฌ(GUI)

 

๐Ÿ“ฃ  Postman ์œผ๋กœ GET ์š”์ฒญํ•˜๊ธฐ

1. ์ƒˆ๋กœ์šด ํƒญ ์˜คํ”ˆ

โžฐ ์š”์ฒญ/์‘๋‹ต์„ ์—ฌ๋Ÿฌ ๊ฐœ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

 

2. HTTP ๋ฉ”์„œ๋“œ ์„ ํƒ

โžฐ GET, POST, DELETE ๋“ฑ์˜ ๋ฉ”์„œ๋“œ ์ค‘ ํ•˜๋‚˜๋ฅผ ์„ ํƒํ•œ๋‹ค.

 

3. URL ์ž…๋ ฅ ์ฐฝ

โžฐ URL๊ณผ Endpoint๋ฅผ ์ž…๋ ฅํ•œ๋‹ค.

 

4. HTTP ์š”์ฒญ ๋ฒ„ํŠผ

โžฐ ์š”์ฒญ์„ ๋ณด๋‚ธ๋‹ค.

 

5. HTTP ์š”์ฒญ ์‹œ ์„ค์ •ํ•  ์ˆ˜ ์žˆ๋Š” ๊ฐ์ข… ์˜ต์…˜

โžฐ ์ถ”๊ฐ€์ ์ธ ํŒŒ๋ผ๋ฏธํ„ฐ๋‚˜, ์š”์ฒญ ๋ณธ๋ฌธ(body)๋ฅผ ์ถ”๊ฐ€ํ•  ์ˆ˜ ์žˆ๋‹ค.

 

6. HTTP ์‘๋‹ต ํ™”๋ฉด

 

๐Ÿ“ฃ  Postman ์œผ๋กœ POST ์š”์ฒญํ•˜๊ธฐ

โœ”๏ธ GET ์š”์ฒญ๊ณผ ๋‹ค๋ฅด๊ฒŒ ๋ณธ๋ฌธ(body)๋ฅผ ์š”์ฒญํ•˜๋Š” ๊ฒฝ์šฐ๊ฐ€ ๋งŽ๋‹ค. (5๋ฒˆ์— Body ํƒญ ํด๋ฆญํ•ด์„œ ์ž…๋ ฅํ•œ๋‹ค)

โžฐ ๋ณธ๋ฌธ์˜ ํ˜•์‹ : JSON ํ˜•์‹์œผ๋กœ ๋ณด๋‚ผ ๋•Œ๋Š” raw -> JSON์„ ์„ ํƒํ•œ๋‹ค.

โžฐ ์ด ๊ณผ์ •์€ HTTP ์š”์ฒญ ํ—ค๋”์— ๋ฐ‘์˜ ์ฝ”๋“œ์ฒ˜๋Ÿผ ์ž…๋ ฅํ•˜๋Š” ๊ฒƒ๊ณผ ๋™์ผ

Content-Type: application/json

โžฐ ๋ณธ๋ฌธ ๋‚ด์šฉ : ์œ ํšจํ•œ JSON(username, text, roomname)์„ ํ˜•์‹์— ๋งž๊ฒŒ ์ ์–ด์ค˜์•ผ ํ•œ๋‹ค.

 

๐Ÿ“ฃ  ์‘๋‹ต ์‚ดํŽด๋ณด๊ธฐ

โœ”๏ธ ์š”์ฒญ์ด ๋๋‚˜์ง€ ์•Š์•„์š”!
โžฐ ์„œ๋ฒ„๊ฐ€ ์š”์ฒญ์— ๋Œ€ํ•œ ์‘๋‹ต์„ ํ•˜์ง€ ์•Š๋Š” ๊ฒฝ์šฐ, ์š”์ฒญ์ด ๋๋‚˜์ง€ ์•Š๋Š”๋‹ค.

โžฐ ์ด ๊ฒฝ์šฐ ์„œ๋ฒ„์˜ ๋ฌธ์ œ

 

โœ”๏ธ ๊ธฐ๋Œ€ํ–ˆ๋˜ ์‘๋‹ต์ด ์˜ค์ง€ ์•Š์•„์š”!

โžฐ ๊ฒฐ๊ณผ์— ์•„๋ฌด๊ฒƒ๋„ ๋‚˜์˜ค์ง€ ์•Š๊ฑฐ๋‚˜, ๊ธฐ๋Œ€ํ–ˆ๋˜ ๊ฐ’์ด ๋‚˜์˜ค์ง€ ์•Š์€ ๊ฒฝ์šฐ

โžฐ HTTP ์‘๋‹ต ์ฝ”๋“œ๋ฅผ ํ™•์ธํ•œ๋‹ค -> 400 Bad Request ์ธ ๊ฒฝ์šฐ ์ž˜๋ชป๋œ ์š”์ฒญ์„ ํ•œ ๊ฒƒ

 

๐Ÿ“ฃ  Postman ์œผ๋กœ ๋‚ ์”จ ๋ฐ›์•„์˜ค๊ธฐ

๐Ÿšจ Open Weather ์— ์ฒ˜์Œ์œผ๋กœ ๊ฐ€์ž…ํ•˜๋ฉด API Key ๋ฐœ๊ธ‰ ๋ฐ›๊ณ  ์–ด๋Š ์ •๋„์˜ ์‹œ๊ฐ„์ด ์žˆ์–ด์•ผ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•˜๋‹ค.

     ๋ฐ‘์˜ ์ฝ”๋“œ์— ๋‚ด API Key ๊ทธ๋Œ€๋กœ ์ผ๋Š”๋ฐ ๊ณ„์† ์—๋Ÿฌ๋‚˜์„œ  ๋งŽ์ด ํ—ค๋งธ๋Š”๋ฐ ๊ตฌ๊ธ€๋ง ํ•ด๋ณด๋‹ˆ๊นŒ ๊ทธ๋ ‡๋‹ค๋”๋ผ..

api.openweathermap.org/data/2.5/weather?id=1835848&appid={your api key}

 

โžฐ ํฌ๋กฌ ํ™•์žฅ ํ”„๋กœ๊ทธ๋žจ JSON Viewer ์“ฐ๋ฉด ๋ฐ์ดํ„ฐ๋ฅผ ๊ตฌ์กฐ์ ์œผ๋กœ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

๐Ÿšจ postman url์— ๋ฐ‘์˜ ์ฝ”๋“œ ์ ์—ˆ๋Š”๋ฐ ์ž๊พธ

' Mixed Content Error: The request has been blocked because it requested an insecure HTTP resource '

์ด๋Ÿฐ ์—๋Ÿฌ๊ฐ€ ๋– ์„œ ๊ตฌ๊ธ€๋ง ํ•ด๋ดค๋Š”๋ฐ insecure HTTP ์š”์ฒญ์ด๋ผ๊ณ  ํ•ด์„œ Postman์—์„œ ํ•ด๋‹น request ์ž์ฒด๋ฅผ ํ•˜์ง€ ์•Š๋Š”๋‹ค๊ณ  ํ•œ๋‹ค.

api.openweathermap.org/data/2.5/weather?q=Seoul&appid={๋‚ด API KEY}

โžฐ URL์— https://cors-anywhere.herokuapp.com/๋ฅผ ์ถ”๊ฐ€ํ•˜๋ฉด ๋ณด์•ˆ ์ฒ˜๋ฆฌ๊ฐ€ ๋œ ๊ฑธ๋กœ ์ธ์‹ํ•œ๋‹ค๊ณ  ํ•ด์„œ

https://cors-anywhere.herokuapp.com/api.openweathermap.org/data/2.5/weather?q=Seoul&appid={๋‚ด API Key}

์ด๋ ‡๊ฒŒ ํ–ˆ๋”๋‹ˆ ์ž˜ ๋˜๋”๋ผ!!!