다음을 통해 공유


내 앱이 프로덕션 수준 API를 사용하고 있는지 확인하는 방법

앱을 빌드할 때 아직 미리 보기 단계의 API를 사용하고 있을 때가 있습니다. 앱과 함께 빌드되는 새 기능과 통합할 때 미리 보기 API를 사용하는 경우가 많습니다. 앱을 프로덕션으로 릴리스하기 전에 프로덕션 수준 API를 사용 중인지 확인해야 합니다. SLA(서비스 수준 계약)가 지원되고 적용되는 안정적인 API를 사용하는 경우 앱이 더욱 견고해 집니다.

앱이 프로덕션 수준 API를 사용하고 있는지 확인하려면 플러그 인을 ApiCenterProductionVersionPlugin 사용할 수 있습니다. 이 플러그 인은 앱의 API 요청에 대한 정보와 Azure API 센터의 정보 및 비프로덕션 API 요청에 대한 보고서를 비교합니다. 또한 사용 중인 프로덕션 버전의 API를 권장합니다.

기록된 API 요청이 Azure API Center에 등록된 프로덕션 버전 API와 일치하는지 확인하는 개발자 프록시를 보여 주는 콘솔의 스크린샷.

시작하기 전에

비프로덕션 API 요청을 검색하려면 조직에서 사용하는 API에 대한 정보가 포함된 Azure API 센터 인스턴스가 있어야 합니다.

Azure API Center 인스턴스 만들기

시작하기 전에 Azure API 센터 인스턴스를 만들고 조직에서 사용하는 API를 등록합니다. API마다 사용하는 버전을 정의하고 수명 주기 단계를 지정합니다.

다른 버전의 API를 보여 주는 Azure API 센터의 스크린샷

ApiCenterProductionVersionPlugin 정보를 사용하여 앱이 사용 중인 API가 프로덕션 또는 비프로덕션 API에 속하는지 확인합니다.

API Center 정보 복사

Azure API Center 인스턴스 개요 페이지에서 API Center 인스턴스의 이름, 리소스 그룹 이름 및 구독 ID를 복사합니다. Azure API Center 인스턴스에 연결할 수 있도록 ApiCenterProductionVersionPlugin을 구성하려면 이 정보가 필요합니다.

여러 속성이 강조 표시된 Azure API Center 개요 페이지의 스크린샷

개발 프록시 구성

앱이 프로덕션 수준 API를 사용하고 있는지 확인하려면 개발자 프록시 구성 파일에서 ApiCenterProductionVersionPlugin을 사용하도록 설정해야 합니다. 앱에서 사용하는 API 보고서를 만들려면 보고자를 추가합니다.

ApiCenterProductionVersionPlugin 사용

devproxyrc.json 파일에서 다음 구성을 추가합니다.

{
  "$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v0.24.0/rc.schema.json",
  "plugins": [
    {
      "name": "ApiCenterProductionVersionPlugin",
      "enabled": true,
      "pluginPath": "~appFolder/plugins/dev-proxy-plugins.dll",
      "configSection": "apiCenterProductionVersionPlugin"
    }
  ],
  "urlsToWatch": [
    "https://jsonplaceholder.typicode.com/*"
  ],
  "apiCenterProductionVersionPlugin": {
    "subscriptionId": "aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e",
    "resourceGroupName": "demo",
    "serviceName": "contoso-api-center",
    "workspaceName": "default"
  }
}

subscriptionId, resourceGroupNameserviceName 속성에서 Azure API Center 인스턴스에 대한 정보를 제공합니다.

urlsToWatch 속성에서 앱이 사용하는 URL을 지정합니다.

개발 프록시 도구 키트 Visual Studio Code 확장을 사용하면 개발 프록시 구성을 쉽게 관리할 수 있습니다.

보고자 추가

ApiCenterProductionVersionPlugin은 앱이 사용하는 API에 대한 보고서를 생성합니다. 이 보고서를 보려면 개발 프록시 구성 파일에 보고자를 추가합니다. 개발 프록시는 여러 보고자를 제공합니다. 이 예에서는 일반 텍스트 보고자를 사용합니다.

일반 텍스트 보고자에 대한 참조를 사용하여 devproxyrc.json 파일을 업데이트합니다.

{
  "$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v0.24.0/rc.schema.json",
  "plugins": [
    {
      "name": "ApiCenterProductionVersionPlugin",
      "enabled": true,
      "pluginPath": "~appFolder/plugins/dev-proxy-plugins.dll",
      "configSection": "apiCenterProductionVersionPlugin"
    },
    {
      "name": "PlainTextReporter",
      "enabled": true,
      "pluginPath": "~appFolder/plugins/dev-proxy-plugins.dll"
    }
  ],
  "urlsToWatch": [
    "https://jsonplaceholder.typicode.com/*"
  ],
  "apiCenterProductionVersionPlugin": {
    "subscriptionId": "aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e",
    "resourceGroupName": "demo",
    "serviceName": "contoso-api-center",
    "workspaceName": "default"
  }
}

앱이 프로덕션 수준 API를 사용하고 있는지 확인

앱이 프로덕션 수준 API를 사용하고 있는지 확인하려면 Azure 구독에 연결하고 개발자 프록시를 실행한 후 앱에서 API 요청을 가로채도록 합니다. 그런 다음 개발자 프록시는 API 요청에 대한 정보를 Azure API Center의 정보와 비교하고 API Center에 등록되지 않은 모든 비프로덕션 API를 보고합니다.

Azure 구독에 연결

개발자 프록시는 Azure API Center의 정보를 사용하여 앱에서 사용하는 API가 프로덕션 수준인지 확인합니다. 이 정보를 가져오려면 Azure 구독에 연결해야 합니다. 여러 가지 방법으로 Azure 구독에 연결할 수 있습니다.

개발 프록시 실행

Azure 구독에 연결한 후 개발 프록시를 시작합니다. devproxyrc.json 파일이 있는 동일한 폴더에서 개발 프록시를 시작하면 구성이 자동으로 로드됩니다. 그렇지 않으면 --config-file 옵션을 사용하여 구성 파일의 경로를 지정합니다.

개발 프록시가 시작되면 Azure 구독에 연결할 수 있는지 확인합니다. 연결에 성공하면 다음과 유사한 메시지가 표시됩니다.

 info    Plugin ApiCenterProductionVersionPlugin connecting to Azure...
 info    Listening on 127.0.0.1:8000...

Hotkeys: issue (w)eb request, (r)ecord, (s)top recording, (c)lear screen
Press CTRL+C to stop Dev Proxy

앱에서 API 요청 기록을 시작하려면 r을 누릅니다.

앱 사용

평소처럼 앱을 사용합니다. 개발 프록시는 API 요청을 가로채서 이에 대한 정보를 메모리에 저장합니다. 개발 프록시가 실행되는 명령줄에서 앱이 생성하는 API 요청에 대한 정보를 확인해야 합니다.

 info    Plugin ApiCenterProductionVersionPlugin connecting to Azure...
 info    Listening on 127.0.0.1:8000...

Hotkeys: issue (w)eb request, (r)ecord, (s)top recording, (c)lear screen
Press CTRL+C to stop Dev Proxy

◉ Recording... 

 req   ╭ GET https://jsonplaceholder.typicode.com/posts?api-version=v1.0
 api   ╰ Passed through

 req   ╭ GET https://jsonplaceholder.typicode.com/users?api-version=beta
 api   ╰ Passed through

API 버전 확인

s를 눌러 녹음을 중지합니다. 개발 프록시는 API Center 인스턴스에 연결하고 요청에 대한 정보를 API Center의 정보와 비교합니다.

 info    Plugin ApiCenterProductionVersionPlugin connecting to Azure...
 info    Listening on 127.0.0.1:8000...

Hotkeys: issue (w)eb request, (r)ecord, (s)top recording, (c)lear screen
Press CTRL+C to stop Dev Proxy

◉ Recording... 

 req   ╭ GET https://jsonplaceholder.typicode.com/posts?api-version=v1.0
 api   ╰ Passed through

 req   ╭ GET https://jsonplaceholder.typicode.com/users?api-version=beta
 api   ╰ Passed through
○ Stopped recording
 info    Checking if recorded API requests use production APIs as defined in API Center...
 info    Loading APIs from API Center...
 info    Analyzing recorded requests...
 warn    Request GET https://jsonplaceholder.typicode.com/users?api-version=beta uses API version beta which is defined as Preview. Upgrade to a production version of the API. Recommended versions: v1.0
 info    DONE

개발 프록시는 분석을 마치면 다음 콘텐츠가 포함된 ApiCenterProductionVersionPlugin_PlainTextReporter.txt라는 파일에 보고서를 만듭니다.

Non-production APIs:

  GET https://jsonplaceholder.typicode.com/users?api-version=beta
  
Production APIs:

  GET https://jsonplaceholder.typicode.com/posts?api-version=v1.0

요약

이 기능을 사용하여 앱이 ApiCenterProductionVersionPlugin프로덕션 수준 API를 사용하고 있는지 확인할 수 있습니다. 이 플러그 인은 API 요청에 대한 정보를 Azure API Center의 정보와 비교하고 비프로덕션 API 요청을 보고합니다. 또한 사용 중인 프로덕션 버전의 API를 권장합니다. 앱이 사용하는 API를 확인하면 SLA가 지원되고 적용되는 안정적인 API를 앱이 사용하여 앱을 더욱 견고하게 만들 수 있습니다. 이 검사를 수동으로 실행하거나 CI/CD 파이프라인과 통합하여 앱이 프로덕션에 출시되기 전에 프로덕션 수준 API를 사용하고 있는지 확인할 수 있습니다.

자세한 정보