Sending API requests to Cloud Feeds

This Getting Started Guide shows you how to send requests by using cURL.

📘

Info

You can also use Rackspace Cloud API services by using the following methods:

Using cURL

cURL is a command-line tool that you can use to interact with REST interfaces. cURL lets you transmit and receive HTTP requests and responses from the command line or a shell script, which enables you to work with the API directly. cURL is available for Linux distributions, Mac OS® X, and Microsoft Windows®. For information about cURL, see http://curl.haxx.se/.

To run the cURL request examples shown in this guide, copy each example from the HTML version of this guide directly to the command line or a script.

🚧

Warning

The cURL examples in this guide are provided for reference only. Because the use of cURL has environmental dependencies, copying and pasting the examples might not work in your environment.

The following example shows a cURL command for sending an authentication request to theIdentity service.

cURL command example: JSON request

In this example, $apiKey is an environment variable that stores your
API key value. Environment variables make it easier to reference account
information in API requests, to reuse the same cURL commands with
different credentials, and also to keep sensitive information like your
API key from being exposed when you send requests to Rackspace Cloud API
services. For details about creating environment variables, see
Configure environment variables.

📘

Info

The carriage returns in the cURL request examples use a backslash (\) as an escape character. The escape character allows continuation of the command across multiple lines.

The cURL examples in this guide use the following command-line options.

OptionDescription
-dSends the specified data in a POST request to the HTTP server. Use this option to send a JSON request body to the server.
-H

Specifies an extra HTTP header in the request. You can specify any number of extra headers. Precede each header with the -H option.

Common headers in Rackspace API requests are as follows:

Content-Type: Required for operations with a request body.

  • Specifies the format of the request body. Following is the syntax for the header where format is json:

    Content-Type: application/json

X-Auth-Token: Required.

  • Specifies the authentication token.

X-Auth-Project-Id: Optional.

  • Specifies the project ID, which can be your account number or another value.

Accept: Optional.

  • Specifies the format of the response body. Following is the syntax for the header where the format is json, which is the default:

    Accept: application/json
-iIncludes the HTTP header in the output.
-sSpecifies silent or quiet mode, which makes cURL mute. No progress or error messages are shown.
-TTransfers the specified local file to the remote URL.
-XSpecifies the request method to use when communicating with the HTTP server. The specified request is used instead of the default method, which is GET.

For commands that return a response, use json.tool to pretty-print the
output by appending the following command to the cURL call:

| python -m json.tool

📘

Info

To use json.tool, import the JSON module. For information about json.tool, see JSON encoder and decoder.

If you run a Python version earlier than 2.6, import the simplejson module and use simplejson.tool. For information about simplejson.tool, see simplejson encoder and decoder.

If you do not want to pretty-print JSON output, omit this code.