API Gateway, diğer Alibaba Cloud kullanıcılarının veya üçüncü taraf hizmet sağlayıcılarının API hizmetlerini çağırmasına olanak tanır. API Gateway ayrıca çeşitli yönetim ve destek hizmetleri sunar.
Bir API Çağırma
Bir API'yi çağırmak için API Gateway konsolunda sunulan çok dilli SDK'ları kullanabilirsiniz (SDK'ları ve belgeleri indirin). Alternatif olarak, API'yi çağırmak üzere kendi HTTP veya HTTPS isteklerinizi de yazabilirsiniz.
Aşağıdaki bölümlerde API çağrıları açıklanmakta ve örnekler verilmektedir:
-
İstek
Bir istek URL'si bir alan adından ve bir yoldan oluşur.
API grubuna bağlı olan alan adını kullanın. Gruba bir alan adı bağlı değilse grubun ikinci düzey alan adını kullanın.
http://e710888d3ccb4638a723ff8d03837095-cn-qingdao.aliapi.com/demo/postİstek yöntemi:
POSTİstek gövdesi:
FormParam1=FormParamValue1&FormParam2=FormParamValue2 # HTTP Request Bodyİstek üstbilgisi:
Host: e710888d3ccb4638a723ff8d03837095-cn-qingdao.aliapi.com Date: Mon, 22 Aug 2016 11:21:04 GMT User-Agent: Apache-HttpClient/4.1.2 (java 1.6) Content-Type: application/x-www-form-urlencoded; charset=UTF-8 # The type of the request body. Set this based on the actual content of the request body. Accept: application/json # The type of the response body. Some APIs return data in a specific format based on the specified response type. Manually specify this request header. If this header is not specified, some HTTP clients use the default value */*, which may cause a signature error. X-Ca-Request-Mode: debug # Specifies whether to enable debug mode. This parameter is not case-sensitive. If this parameter is not specified, debug mode is disabled by default. Enable this mode during the API debugging phase. X-Ca-Version: 1 # The version number of the API. All APIs support only version 1. You can leave this request header unspecified. The default version number is 1. X-Ca-Signature-Headers: X-Ca-Request-Mode,X-Ca-Version,X-Ca-Stage,X-Ca-Key,X-Ca-Timestamp # The custom request headers that are included in the signature calculation. The server reads the request headers based on this configuration to sign the request. This configuration does not include the Content-Type, Accept, Content-MD5, and Date request headers. These headers are already included in the basic signature structure. For more information, see the request signature documentation. X-Ca-Stage: RELEASE # The stage of the API. Valid values: TEST, PRE, and RELEASE. This parameter is not case-sensitive. The API provider can select the stage to which the API is published. The API can be called only after it is published to the specified stage. Otherwise, the system reports that the API is not found or the URL is invalid. X-Ca-Key: 60022326 # The AppKey of the request. Generate the AppKey in the API Gateway console. An API can be called only after it is authorized. By default, APIs purchased from channels such as Alibaba Cloud Marketplace are already authorized for the app. All Alibaba Cloud products share one AppKey system. Delete an AppKey with caution to avoid affecting other activated Alibaba Cloud products. X-Ca-Timestamp: 1471864864235 # The timestamp of the request. This value is the number of milliseconds that have elapsed since 00:00:00 UTC on January 1, 1970. The timestamp is valid for 15 minutes. X-Ca-Nonce:b931bc77-645a-4299-b24b-f3669be577ac # The unique ID of the request. The combination of AppKey, API, and Nonce must be unique within 15 minutes. This parameter is used with the timestamp to prevent replay attacks. X-Ca-Signature: FJleSrCYPGCU7dMlLTG+UD3Bc5Elh3TV3CWHtSKh1Ys= # The request signature. CustomHeader: CustomHeaderValue # A custom request header. This is only an example. In an actual request, you can set multiple custom request headers based on the API definition. -
Yanıt
Durum kodu:
400 # The status code of the response. A value from 200 to 299 indicates success. A value from 400 to 499 indicates a client error. A value of 500 or greater indicates a server error.Yanıt üstbilgisi:
X-Ca-Request-Id: 7AD052CB-EE8B-4DFD-BBAF-EFB340E0A5AF # The unique ID of the request. After a request enters API Gateway, API Gateway generates a request ID and returns it to the client in the response header. Record this request ID on both the client and the backend service for troubleshooting and tracking. X-Ca-Error-Message: Invalid Url # The error message returned by API Gateway. If an error occurs in a request, API Gateway returns the error message to the client in a response header. X-Ca-Debug-Info: {"ServiceLatency":0,"TotalLatency":2} # If debug mode is enabled, debug information is returned. This information may change and is for reference only during the joint debugging phase.
HTTP veya HTTPS kullanmanızdan bağımsız olarak, bir API çağrılırken istek imza bilgilerini içermelidir. AppKey kimliğinizi belirler; AppSecret ise imza dizisini şifrelemek ve sunucuda imzayı doğrulamak için kullanılan anahtardır. Şifrelenmiş imzanın nasıl hesaplanacağı ve iletileceği hakkında daha fazla bilgi için bkz. Bir API'yi çağırmak için özet kimlik doğrulamayı kullanma.
İmzaların nasıl hesaplanacağına ilişkin örnek kodlar için API Gateway konsolundaki SDK'ları İndir sayfasındaki SDK örneklerine bakın.
Daha fazla bilgi için bkz. Genel Bakış.