REST API에 GET Request 제출
rpc
명령어의 경우, 엔드포인트의 일반적인 형식은
scheme://device-name:port/rpc/method[@attributes]/params
scheme
:http
또는https
method
: 모든 명령어의rpc
Junos OS. 이름은method
태그 요소와 동일합니다. 자세한 내용은 Junos XML API운영 개발자 참조 를 참조하십시오.params
: 옵션 매개 변수name[=value]
값().
요청을 인증하기 위해, Authorization 헤더에 포함된 기본64 인코딩된 사용자 이름과 암호를 제출하십시오.
curl -u "username:password" http://device-name:port/rpc/get-interface-information
GET 요청을 위한 URI에서 데이터를 쿼리 문자열로 지정하기 위해 여러 인수를 구분하는 구분자와 다음 URI를 사용하거나 이와 동일한 rpc
cURL 호출에 표시된처럼 디리미터를 사용할 수 ?
&
/
있습니다.
예를 들어:
curl -u "username:password" http://device-name:port/rpc/get-interface-information?interface-name=cbp0&snmp-index=1
curl -u "username:password" http://device-name:port/rpc/get-interface-information/interface-name=cbp0/snmp-index=1
HTTP Accept 헤더는 다음 Content-Type 값 중 하나를 사용하여 반환 형식을 지정할 수 있습니다.
애플리케이션/xml(기본)
애플리케이션/json
텍스트/일반
텍스트/html
예를 들어, 다음 cURL 호출은 JSON의 출력 형식을 지정합니다.
curl -u "username:password" http://device-name:port/rpc/get-interface-information?interface-name=cbp0 –header "Accept: application/json"
옵션 매개 변수를 사용하여 출력 형식을 지정할 수도 format
있습니다.
예를 들어, 태그 요소는 소프트웨어 프로세스 개정 수준을 <get-software-information>
검색합니다. 다음 HTTPS GET 요청은 이 명령을 실행하고 JSON 형식으로 결과를 검색합니다.
https://device-name:3000/rpc/get-software-information@format=json
다음 Python 프로그램은 REST 인터페이스를 사용하여 RPC를 실행하고, 응답에서 데이터를 추출하고, CPU 로드 평균 그래프를 get-route-engine-information
플롯합니다.
import numpy as np import matplotlib.pyplot as plt import matplotlib.animation as animation import requests temp_y = 1 def update_line(num, data, line): if num == 0: return line, global temp_y x_data.append(num) if num is not 0 and num%8 == 1: r = requests.get('scheme://device:port/rpc/get-route-engine-information@format=json', auth=('username', 'password')) if r: temp_y = r.json()["route-engine-information"][0]["route-engine"][0]["load-average-one"][0]["data"] y_data.append(temp_y) line.set_data(x_data, y_data) return line, fig1 = plt.figure() x_data = [] y_data = [] l, = plt.plot([], []) plt.xlim(0, 80) plt.ylim(0, 1.5) plt.xlabel('Time in seconds') plt.ylabel('CPU utilization (load average)') plt.title('REST-API test') line_ani = animation.FuncAnimation(fig1, update_line, 80, fargs=(0, l), interval=1000, blit=True) plt.show()
![](/documentation/us/en/software/junos/rest-api/images/s002893.png)