

# Invoke REST APIs in API Gateway
<a name="how-to-call-api"></a>

To call a deployed API, clients submit requests to the URL for the API Gateway component service for API execution, known as `execute-api`.

The base URL for REST APIs is in the following format: 

```
https://api-id.execute-api.region.amazonaws.com/stage/
```

where *api-id* is the API identifier, *region* is the Amazon Region, and *stage* is the stage name of the API deployment. 

**Important**  
Before you can invoke an API, you must deploy it in API Gateway. For instructions on deploying an API, see [Deploy REST APIs in API Gateway](how-to-deploy-api.md). 

**Topics**
+ [Obtaining an API's invoke URL](#apigateway-how-to-call-rest-api)
+ [Invoking an API](#apigateway-call-api)
+ [Use the API Gateway console to test a REST API method](how-to-test-method.md)
+ [Use a Java SDK generated by API Gateway for a REST API](how-to-call-apigateway-generated-java-sdk.md)
+ [Use an Android SDK generated by API Gateway for a REST API](how-to-generate-sdk-android.md)
+ [Use a JavaScript SDK generated by API Gateway for a REST API](how-to-generate-sdk-javascript.md)
+ [Use a Ruby SDK generated by API Gateway for a REST API](how-to-call-sdk-ruby.md)
+ [Use iOS SDK generated by API Gateway for a REST API in Objective-C or Swift](how-to-generate-sdk-ios.md)

## Obtaining an API's invoke URL
<a name="apigateway-how-to-call-rest-api"></a>

You can use the console, the Amazon CLI, or an exported OpenAPI definition to obtain an API's invoke URL.

### Obtaining an API's invoke URL using the console
<a name="apigateway-obtain-url-console"></a>

The following procedure shows how to obtain an API's invoke URL in the REST API console.

**To obtain an API's invoke URL using the REST API console**

1. Sign in to the API Gateway console at [https://console.amazonaws.cn/apigateway](https://console.amazonaws.cn/apigateway).

1. Choose a deployed API.

1. From the main navigation pane, choose **Stage**.

1. Under **Stage details**, choose the copy icon to copy your API's invoke URL.

   This URL is for the root resource of your API.

1. To obtain an API's invoke URL for another resource in your API, expand the stage under the secondary navigation pane, and then choose a method.

1. Choose the copy icon to copy your API's resource-level invoke URL.

#### Obtaining an API's invoke URL using the Amazon CLI
<a name="apigateway-obtain-url-cli"></a>

The following procedure shows how to obtain an API's invoke URL using the Amazon CLI.

**To obtain an API's invoke URL using the Amazon CLI**

1. Use the following command to obtain the `rest-api-id`. This command returns all `rest-api-id` values in your Region. For more information, see [get-rest-apis](https://docs.amazonaws.cn/cli/latest/reference/apigateway/get-rest-apis.html).

   ```
   aws apigateway get-rest-apis
   ```

1. Replace the example `rest-api-id` with your `rest-api-id`, replace the example *\$1stage-name\$1* with your *\$1stage-name\$1*, and replace the *\$1region\$1*, with your Region.

   ```
   https://{restapi_id}.execute-api.{region}.amazonaws.com/{stage_name}/
   ```

##### Obtaining an API's invoke URL using the exported OpenAPI definition file of the API
<a name="apigateway-obtain-url-openapi"></a>

You can also construct the root URL by combining the `host` and `basePath` fields of an exported OpenAPI definition file of the API. For instructions on how to export your API, see [Export a REST API from API Gateway](api-gateway-export-api.md).

## Invoking an API
<a name="apigateway-call-api"></a>

You can call your deployed API using the browser, curl, or other applications, like [Postman](https://www.postman.com/).

Additionally, you can use the API Gateway console to test an API call. Test uses the API Gateway's `TestInvoke` feature, which allows API testing before the API is deployed. For more information, see [Use the API Gateway console to test a REST API method](how-to-test-method.md).

**Note**  
Query string parameter values in an invocation URL cannot contain `%%`.

### Invoking an API using a web browser
<a name="apigateway-call-api-brower"></a>

If your API permits anonymous access, you can use any web browser to invoke any `GET` method. Enter the complete invocation URL in the browser's address bar.

For other methods or any authentication-required calls, you must specify a payload or sign the requests. You can handle these in a script behind an HTML page or in a client application using one of the Amazon SDKs.

#### Invoking an API using curl
<a name="apigateway-call-api-curl"></a>

You can use a tool like [curl](https://curl.se/) in your terminal to call your API. The following example curl command invokes the GET method on the `getUsers` resource of the `prod` stage of an API.

------
#### [ Linux or Macintosh ]

```
curl -X GET 'https://b123abcde4.execute-api.us-west-2.amazonaws.com/prod/getUsers'
```

------
#### [ Windows ]

```
curl -X GET "https://b123abcde4.execute-api.us-west-2.amazonaws.com/prod/getUsers"
```

------