API 참조로 작업하는 방법
이 섹션에서는 상호작용의 예와 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