API 참조 자료 활용 방법
Updated:
이 섹션에서는 상호작용의 예시와 API에서 매개변수를 사용하는 방법을 살펴보겠습니다.
이 예제에서 사용된 모든 데이터는 가상의 데이터이며, 오직 시연 목적으로만 제공됩니다. API를 사용할 때는 항상 유효한 실제 데이터를 사용하십시오.
종점:
PATCHhttps://mobile.proxy-seller.com/api/v1/hosts/{hostId}/changeName
자세히 살펴보세요
PATCH -는 쿼리에 사용된 메서드를 나타냅니다.
{hostId} -는 유효한 값으로 대체해야 할 변수를 나타냅니다.
경로 매개변수
이름 | 유형 | 설명 |
|---|---|---|
hostId* | 문자열 | 호스트 ID |
헤더
이름 | 값 |
|---|---|
콘텐츠 유형 |
|
승인* |
|
요청 본문
이름 | 유형 | 설명 |
|---|---|---|
이름* | 문자열 | 새로운 호스트 이름 |
모든 필수 입력 항목에는 별표(*)가 표시되어 있습니다.
예시
https://mobile.proxy-seller.com/api/v1/hosts/21vjv1224n45v7457mvcas/changeName쿼리에는 다양한 매개변수 집합과 유형이 있을 수 있습니다. 아래 그림을 참조하십시오.
여러 프로그래밍 언어에서의 사용 예를 살펴보겠습니다.
curl -X PATCH \
-H "Content-Type: application/json" \
-H "Authorization: YOUR_API_KEY" \
-d '{"name":"Host new name"}' \
"https://mobile.proxy-seller.com/api/v1/hosts/ID_OF_SOME_HOST/changeName"
User
import fetch from 'node-fetch';
const apiKey = "YOUR_API_KEY";
const hostId = "ID_OF_SOME_HOST";
// add path parameter to request
const url = "https://mobile.proxy-seller.com/api/v1/hosts/" + hostId + "/changeName";
// also "query" parameters are added here
// const urlWithQuery = url + "?someNameParameter=someValue"
const body = {
name: "Host new name",
// write here your body params
};
const response = await fetch(url, {
method: 'patch',
// add headers parameters to request
headers: {
'Content-Type': 'application/json', // it is impotent to body parameters
'Authorization': apiKey,
// write here your other headers params
},
// add body parameters to request
body: JSON.stringify(body)
});
console.log(await response.json()); try {
String apiKey = "YOUR_API_KEY";
String hostId = "ID_OF_SOME_HOST";
String url = "https://mobile.proxy-seller.com/api/v1/hosts/" + hostId + "/changeName";
// also "query" parameters are added here
// String urlWithQuery = url + "?someNameParameter=someValue"
// Constructing the request body
String body = "{\"name\": \"Host new name"}";
// Creating URL object
URL obj = new URL(url);
// Creating HTTPURLConnection
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
// Setting the request method
con.setRequestMethod("PATCH");
// Setting headers
con.setRequestProperty("Content-Type", "application/json");
con.setRequestProperty("Authorization", apiKey);
// Enabling the connection to send and receive data
con.setDoOutput(true);
// Writing the request body
DataOutputStream wr = new DataOutputStream(con.getOutputStream());
wr.writeBytes(body);
wr.flush();
wr.close();
// Reading the response
int responseCode = con.getResponseCode();
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
// Printing the response
System.out.println(response.toString());
} catch (Exception e) {
e.printStackTrace();
}HTTP 상태 코드별 응답 예시. '200'은 성공을 나타내며, '4XX' 코드는 오류를 나타냅니다.
답변
{
"id": "21vjv1224n45v7457mvcas",
"name": "Host new name",
"number": "101"
}AUTHORIZATION_FAILED,
IP_AUTHORIZATION_FAILED,
HOST_USER_ID_AND_AUTH_DOES_NOT_MATCHINVALID_HOST_ID,HOST_NOT_FOUND