<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        
        <title>
            <![CDATA[ API - freeCodeCamp.org ]]>
        </title>
        <description>
            <![CDATA[ Browse thousands of programming tutorials written by experts. Learn Web Development, Data Science, DevOps, Security, and get developer career advice. ]]>
        </description>
        <link>https://www.freecodecamp.org/korean/news/</link>
        <image>
            <url>https://cdn.freecodecamp.org/universal/favicons/favicon.png</url>
            <title>
                <![CDATA[ API - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/korean/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Tue, 16 Jun 2026 21:15:08 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/korean/news/tag/api/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ Postman 스크립트를 사용해 API 인증 과정 단순화하는 법 ]]>
                </title>
                <description>
                    <![CDATA[ Postman은 개발자, API 테스터, 기술 문서 작성자, DevOps 팀이 API 개발을 테스트하고 문서화하며 협업할 때 사용하는 플랫폼입니다. HTTP, GraphQL, gRPC 등 다양한 형태의 API 요청을 손쉽게 만들고, 응답을 확인하며, API 요청들을 컬렉션 형태로 구성해 협업과 자동화를 지원합니다. API 테스트 과정에서 반복 작업을 수행하는 일은 스트레스도 크고 시간이 많이 소요됩니다. 특히 ]]>
                </description>
                <link>https://www.freecodecamp.org/korean/news/how-to-use-postman-scripts/</link>
                <guid isPermaLink="false">691ba51bb7c1b604cf5881a5</guid>
                
                    <category>
                        <![CDATA[ Authentication ]]>
                    </category>
                
                    <category>
                        <![CDATA[ REST API ]]>
                    </category>
                
                    <category>
                        <![CDATA[ API ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Jong-Ho Kim ]]>
                </dc:creator>
                <pubDate>Tue, 02 Dec 2025 01:00:05 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/korean/news/content/images/2025/11/dc77dc00-a0a6-40f7-b766-ce07d0d8a637-1.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p data-test-label="translation-intro">
        <strong>기사 원문:</strong> <a href="https://www.freecodecamp.org/news/how-to-use-postman-scripts/" target="_blank" rel="noopener noreferrer" data-test-label="original-article-link">How to Use Postman Scripts to Simplify Your API Authentication Process</a>
      </p><p>Postman은 개발자, API 테스터, 기술 문서 작성자, DevOps 팀이 API 개발을 테스트하고 문서화하며 협업할 때 사용하는 플랫폼입니다. HTTP, GraphQL, gRPC 등 다양한 형태의 API 요청을 손쉽게 만들고, 응답을 확인하며, API 요청들을 컬렉션 형태로 구성해 협업과 자동화를 지원합니다.</p><p>API 테스트 과정에서 반복 작업을 수행하는 일은 스트레스도 크고 시간이 많이 소요됩니다. 특히 Postman에서 새 인증 토큰을 받아 복사해서 붙여넣는 작업은 매우 반복적입니다. Postman 스크립트를 사용하면 인증 토큰을 자동으로 저장하고 재사용할 수 있어 이러한 반복 작업을 줄일 수 있습니다.</p><p>이 가이드를 따라 해보려면 다음이 필요합니다:</p><ul><li><a href="https://www.postman.com/downloads/">Postman API 클라이언트</a>가 설치된 컴퓨터</li><li>Postman으로 API 요청을 만들어본 경험</li><li>JWT 인증을 사용하는 백엔드 애플리케이션과 해당 API 문서</li></ul><p>만약 백엔드 애플리케이션이 없다면, 제가 GitHub에 올려 둔 <a href="https://github.com/orimdominic/freeCodeCamp-postman-api-jwt">예제</a>(orimdominic/freeCodeCamp-postman-api-jwt)를 클론해서 사용할 수 있습니다.</p><p>이 글을 다 읽고 나면, Postman에서 인증 토큰을 발급 / 저장 / 재사용하는 과정을 훨씬 단순화할 수 있습니다. 또한 Postman의 다른 테스트 자동화 작업에도 활용할 수 있는 실용적인 스크립트 개념을 익히게 될 것입니다.</p><h2 id="-">목차</h2><ul><li>Postman 스크립트란?</li><li>JWT 인증 과정을 단순화하는 방법</li><li>인증 요청으로 토큰 받아오기</li><li>Postman 스크립트로 토큰을 변수에 저장하기</li><li>API 요청에서 변수 사용하기</li><li>다음 단계</li></ul><h2 id="postman-">Postman 스크립트란?</h2><p><a href="https://learning.postman.com/docs/tests-and-scripts/tests-and-scripts/">Postman 스크립트</a>는 Postman API 클라이언트 내부에서 실행되는 JavaScript 코드로, API 테스트 워크플로우를 자동화하고 확장하는 데 사용합니다. 스크립트는 요청 전(pre-request)과 요청 후(post-response)에 실행되도록 추가할 수 있습니다. 스크립트를 사용하면 다음과 같은 작업이 가능합니다:</p><ul><li>API 요청 데이터를 처리하는 로직 추가</li><li>API 응답에 대한 테스트(assertion) 작성</li><li>API 엔드포인트 자동화 테스트 실행</li></ul><figure class="kg-card kg-image-card"><img src="https://www.freecodecamp.org/korean/news/content/images/2025/11/161bd327-fbf7-48cb-acab-317ab1cad4c5.jpeg" class="kg-image" alt="161bd327-fbf7-48cb-acab-317ab1cad4c5" srcset="https://www.freecodecamp.org/korean/news/content/images/size/w600/2025/11/161bd327-fbf7-48cb-acab-317ab1cad4c5.jpeg 600w, https://www.freecodecamp.org/korean/news/content/images/2025/11/161bd327-fbf7-48cb-acab-317ab1cad4c5.jpeg 903w" sizes="(min-width: 720px) 720px" width="903" height="493" loading="lazy"></figure><p>Postman의 <strong>Scripts </strong>탭에서 스크립트를 확인할 수 있습니다. <strong>Pre-request</strong> 탭은 요청이 실행되기 전에, <strong>Post-response</strong> 탭은 응답이 온 뒤에 실행됩니다.</p><h2 id="jwt-">JWT 인증 과정을 단순화하는 방법</h2><p>이번 튜토리얼은 다음과 같은 순서대로 진행됩니다:</p><ul><li>인증하여 토큰 발급받기</li><li>스크립트를 사용해 토큰을 컬렉션 변수에 저장하기</li><li>API 요청에서 해당 변수를 사용하기</li></ul><h2 id="--1">인증하여 토큰 발급받기</h2><p>다음과 같은 순서대로 따라해보세요:</p><ol><li>백엔드 애플리케이션을 실행하고 정상적으로 동작하는지 확인합니다.</li><li>Postman을 열고 JWT를 발급받는 로그인(sign-in) 요청으로 이동합니다.</li><li>로그인 엔드포인트에 API 요청을 보내고 JSON 응답 구조를 확인합니다.</li></ol><figure class="kg-card kg-image-card"><img src="https://www.freecodecamp.org/korean/news/content/images/2025/11/b5aad14c-5094-4a84-8876-1bbbb869064c.jpeg" class="kg-image" alt="b5aad14c-5094-4a84-8876-1bbbb869064c" srcset="https://www.freecodecamp.org/korean/news/content/images/size/w600/2025/11/b5aad14c-5094-4a84-8876-1bbbb869064c.jpeg 600w, https://www.freecodecamp.org/korean/news/content/images/size/w1000/2025/11/b5aad14c-5094-4a84-8876-1bbbb869064c.jpeg 1000w, https://www.freecodecamp.org/korean/news/content/images/2025/11/b5aad14c-5094-4a84-8876-1bbbb869064c.jpeg 1416w" sizes="(min-width: 720px) 720px" width="1416" height="623" loading="lazy"></figure><p>위 이미지에서 하이라이트된 부분은 로그인 요청이 성공했을 때 반환되는 JSON 응답을 보여줍니다. 이 응답 스키마에서 인증에 사용할 토큰은 <code>data.token</code> 필드에 포함되어 있습니다. 이제 이 토큰을 Postman 스크립트를 사용해 변수로 저장한 뒤, 인증이 필요한 요청의 <code>Authorization</code> 헤더에서 해당 변수를 사용하게 될 것입니다.</p><h2 id="--2">스크립트를 사용해 토큰을 컬렉션 변수에 저장하기</h2><figure class="kg-card kg-image-card"><img src="https://www.freecodecamp.org/korean/news/content/images/2025/11/2b43493d-2803-45cd-aefe-0ca5694f75e8.jpeg" class="kg-image" alt="2b43493d-2803-45cd-aefe-0ca5694f75e8" srcset="https://www.freecodecamp.org/korean/news/content/images/size/w600/2025/11/2b43493d-2803-45cd-aefe-0ca5694f75e8.jpeg 600w, https://www.freecodecamp.org/korean/news/content/images/size/w1000/2025/11/2b43493d-2803-45cd-aefe-0ca5694f75e8.jpeg 1000w, https://www.freecodecamp.org/korean/news/content/images/2025/11/2b43493d-2803-45cd-aefe-0ca5694f75e8.jpeg 1229w" sizes="(min-width: 720px) 720px" width="1229" height="483" loading="lazy"></figure><p>Postman에서 <strong>Body </strong>탭 옆에 있는 <strong>Scripts </strong>탭을 클릭합니다. 만약 Postman 창이 작게 표시되어 있다면, 해당 탭이 드롭다운 메뉴 안에 있을 수 있으니 펼쳐서 확인합니다. 다음으로 <strong>Post-response</strong> 탭을 선택합니다. 오른쪽의 텍스트 영역에 응답에서 인증 토큰을 추출해 Postman 변수에 저장하는 스크립트를 작성하게 됩니다. 아래 JavaScript 코드를 복사해 이 텍스트 영역에 붙여 넣습니다.</p><pre><code class="language-javascript">if (pm.response.code == 200) {
    const token = pm.response.json().data.token
    pm.collectionVariables.set("auth_token", token)
}</code></pre><p>Postman 스크립트에서는 <a href="https://learning.postman.com/docs/tests-and-scripts/write-scripts/postman-sandbox-reference/overview/"><code>pm</code> 식별자</a>를 사용해 Postman 환경의 정보에 접근하고 값을 수정합니다. 위 스크립트는 먼저 응답 상태 코드가 200인지 확인해 요청이 성공했는지 확인합니다.</p><p>조건문 내부에서는 <code>pm.response.json().data.token</code>을 사용해 JSON 응답에서 인증 토큰을 가져오고, 이를 <code>auth_token</code>이라는 컬렉션 변수에 저장합니다. 만약 <code>auth_token</code> 변수가 없다면 새로 생성되고, 이미 존재한다면 기존 값이 새 토큰 값으로 덮어씁니다.</p><figure class="kg-card kg-image-card"><img src="https://www.freecodecamp.org/korean/news/content/images/2025/11/bed1fe89-9c00-4b94-9f71-173ea3bf1cd1.png" class="kg-image" alt="bed1fe89-9c00-4b94-9f71-173ea3bf1cd1" srcset="https://www.freecodecamp.org/korean/news/content/images/size/w600/2025/11/bed1fe89-9c00-4b94-9f71-173ea3bf1cd1.png 600w, https://www.freecodecamp.org/korean/news/content/images/size/w1000/2025/11/bed1fe89-9c00-4b94-9f71-173ea3bf1cd1.png 1000w, https://www.freecodecamp.org/korean/news/content/images/2025/11/bed1fe89-9c00-4b94-9f71-173ea3bf1cd1.png 1219w" sizes="(min-width: 720px) 720px" width="1219" height="373" loading="lazy"></figure><p>토큰이 변수에 정상적으로 저장되었는지 확인하려면, 위 스크린샷 기준으로 먼저 컬렉션 이름(1)을 클릭한 뒤 <strong>Variables </strong>탭(2)을 선택합니다. 이후에는 인증 토큰을 매번 복사해 <code>Authorization</code> 헤더에 붙여넣을 필요 없이, <code>Authorization</code> 헤더에서 <code>auth_token</code> 변수를 그대로 사용할 수 있습니다.</p><h2 id="api-">API 요청에서 해당 변수를 사용하기</h2><figure class="kg-card kg-image-card"><img src="https://www.freecodecamp.org/korean/news/content/images/2025/11/d3bf0f56-c406-4d3e-b7f1-df4cbc2a3cfc.png" class="kg-image" alt="d3bf0f56-c406-4d3e-b7f1-df4cbc2a3cfc" srcset="https://www.freecodecamp.org/korean/news/content/images/size/w600/2025/11/d3bf0f56-c406-4d3e-b7f1-df4cbc2a3cfc.png 600w, https://www.freecodecamp.org/korean/news/content/images/size/w1000/2025/11/d3bf0f56-c406-4d3e-b7f1-df4cbc2a3cfc.png 1000w, https://www.freecodecamp.org/korean/news/content/images/2025/11/d3bf0f56-c406-4d3e-b7f1-df4cbc2a3cfc.png 1185w" sizes="(min-width: 720px) 720px" width="1185" height="390" loading="lazy"></figure><p><code>Authorization</code> 헤더에서 컬렉션 변수를 사용할 때는 <code>{{auth_token}}</code>처럼 중괄호 두 개로 감싸서 참조합니다. 이렇게 설정해두면, API 요청을 보낼 때 Postman이 <code>{{auth_token}}</code>에 저장된 값을 자동으로 <code>Authorization</code> 헤더에 넣어 사용합니다.</p><p>또 다른 인증 요청으로 인해 <code>auth_token</code> 값이 갱신되더라도, 새로운 토큰을 직접 복사해서 붙여넣을 필요는 없습니다. Post-response 탭에 작성한 스크립트가 자동으로 <code>auth_token</code> 값을 업데이트해 주기 때문에, 이후에도 API 요청을 문제없이 계속 보낼 수 있습니다. 더 이상 반복적인 복사 및 붙여넣기 작업을 할 필요가 없습니다. 즉, <strong>DRY (Don’t Repeat Yourself)</strong> 원칙을 지킬 수 있습니다.</p><h2 id="--3">다음 단계</h2><p>이번 튜토리얼에서는 Postman 스크립트를 사용해 환경 변수를 설정하고, 인증 토큰을 자동으로 저장 및 재사용하는 방법을 배웠습니다.</p><p>API 테스트에 대한 더 많은 예제와 assertion 작성 방법을 알고 싶다면, Postman에서 제공하는 <a href="https://learning.postman.com/docs/tests-and-scripts/test-apis/test-apis/">Test API Functionality and Performance in Postman</a> 가이드를 참고하면 도움이 됩니다.</p> ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
