Há mais exemplos de AWS SDK disponíveis no repositório AWS Doc SDK Examples GitHub .
As traduções são geradas por tradução automática. Em caso de conflito entre o conteúdo da tradução e da versão original em inglês, a versão em inglês prevalecerá.
Use GetRestApis com um AWS SDK ou CLI
Os exemplos de código a seguir mostram como usar o GetRestApis.
Exemplos de ações são trechos de código de programas maiores e devem ser executados em contexto. É possível ver essa ação em contexto nos seguintes exemplos de código:
- CLI
-
- AWS CLI
-
Para obter uma lista de REST APIs
Comando:
aws apigateway get-rest-apis
Saída:
{
"items": [
{
"createdDate": 1438884790,
"id": "12s44z21rb",
"name": "My First API"
}
]
}
- Python
-
- SDK para Python (Boto3)
-
class ApiGatewayToService:
"""
Encapsulates Amazon API Gateway functions that are used to create a REST API that
integrates with another AWS service.
"""
def __init__(self, apig_client):
"""
:param apig_client: A Boto3 API Gateway client.
"""
self.apig_client = apig_client
self.api_id = None
self.root_id = None
self.stage = None
def get_rest_api_id(self, api_name):
"""
Gets the ID of a REST API from its name by searching the list of REST APIs
for the current account. Because names need not be unique, this returns only
the first API with the specified name.
:param api_name: The name of the API to look up.
:return: The ID of the specified API.
"""
try:
rest_api = None
paginator = self.apig_client.get_paginator("get_rest_apis")
for page in paginator.paginate():
rest_api = next(
(item for item in page["items"] if item["name"] == api_name), None
)
if rest_api is not None:
break
self.api_id = rest_api["id"]
logger.info("Found ID %s for API %s.", rest_api["id"], api_name)
except ClientError:
logger.exception("Couldn't find ID for API %s.", api_name)
raise
else:
return rest_api["id"]
- Rust
-
- SDK para Rust
-
Exibe o REST do Amazon API Gateway APIs na região.
async fn show_apis(client: &Client) -> Result<(), Error> {
let resp = client.get_rest_apis().send().await?;
for api in resp.items() {
println!("ID: {}", api.id().unwrap_or_default());
println!("Name: {}", api.name().unwrap_or_default());
println!("Description: {}", api.description().unwrap_or_default());
println!("Version: {}", api.version().unwrap_or_default());
println!(
"Created: {}",
api.created_date().unwrap().to_chrono_utc()?
);
println!();
}
Ok(())
}
- SAP ABAP
-
- SDK para SAP ABAP
-
TRY.
oo_result = lo_agw->getrestapis( ).
DATA(lt_apis) = oo_result->get_items( ).
DATA(lv_count) = lines( lt_apis ).
MESSAGE 'Found ' && lv_count && ' REST APIs' TYPE 'I'.
CATCH /aws1/cx_agwbadrequestex INTO DATA(lo_bad_request).
MESSAGE lo_bad_request->get_text( ) TYPE 'I'.
RAISE EXCEPTION lo_bad_request.
CATCH /aws1/cx_agwtoomanyrequestsex INTO DATA(lo_too_many).
MESSAGE lo_too_many->get_text( ) TYPE 'I'.
RAISE EXCEPTION lo_too_many.
ENDTRY.