Create and manage a service#
You can use the simple examples in the following sections for basic Rackspace CDN requests that you will commonly use to create and manage a service by using Rackspace CDN API operations. Example requests are provided in cURL, followed by the response.
Before running the examples, review the Rackspace CDN concepts.
To start using the API and run the examples in this section, you need the following items:
Rackspace Cloud account. If you don’t have one, sign up for a Rackspace Cloud account.
Username and password to access the account
API key to access Rackspace Cloud services
Account number
Command-line tool or browser client for communicating with the API service.
Note
These examples use the $API_ENDPOINT
, $AUTH_TOKEN
, and
$TENANT_ID
environment variables to specify the API endpoint,
authentication token, and account ID values for accessing the service.
Make sure you
configure these variables before
running the code samples.
For more information about all Rackspace CDN operations, see the API reference.
Creating a service#
A service represents an application that has its content cached to the edge nodes, such as a website. To create a service, issue a POST request and provide a JSON body with the required attributes for the new service. (Each of these attributes is described in the Rackspace CDN Developer Guide in the create service operation description.)
The service defines the domain used to access the website via CDN, and the origin from which to pull content.
Following are examples of a create service request and response.
Example: cURL create a service request
curl -i -X POST $API_ENDPOINT/v1.0/$TENANT_ID/services \
-H "Accept: application/json" \
-H "X-Auth-Token: $AUTH_TOKEN" \
-H "Content-Type: application/json" -d \
'{
"name": "mywebsite.com",
"domains": [
{"domain": "www.mywebsite.com", "protocol": "https"},
{"domain": "blog.mywebsite.com", "protocol": "https"}
],
"origins": [
{
"origin": "mywebsite.com",
"port": 443,
"ssl": false,
"rules": [
]
}
],
"restrictions": [
{
"name": "website only",
"rules": [
{
"name": "mywebsite.com",
"referrer": "www.mywebsite.com"
}
]
}
],
"caching": [
{
"name": "default",
"ttl": 3600
},
{
"name": "home",
"ttl": 17200,
"rules": [
{
"name": "index",
"request_url": "/index.htm"
}
]
},
{
"name": "images",
"ttl": 12800,
"rules": [
{
"name": "images",
"request_url": "*.png"
}
]
}
],
"flavor_id": "cdn"
}'
When the service is created, you see an HTTP 202 response with the
Location
header returned.
Example: Create a service response
HTTP/1.1 202 Accepted
Content-TYpe: application/json
Location: https://global.cdn.api.rackspacecloud.com/v1.0/services/yourServiceID
Retrieving a created service#
Perform a GET request on the Location
header that was returned
in Create a service.
Example: cURL retrieve a service request
curl -i -X GET $API_ENDPOINT/v1.0/$TENANT_ID/services/yourServiceID \
-H "X-Auth-Token: $AUTH_TOKEN" \
-H "Content-type: application/json"
You see a response body similar to the one in the following example.
Example: Retrieve a service response
HTTP/1.1 200 OK
Content-Type: application/json
{
"id": "yourServiceID",
"name": "mywebsite.com",
"domains": [
{
"domain": "www.mywebsite.com",
"protocol": "https"
}
],
"origins": [
{
"origin": "mywebsite.com",
"port": 443,
"ssl": false,
"rules": []
}
],
"caching": [
{
"name": "default",
"ttl": 3600
},
{
"name": "home",
"ttl": 17200,
"rules": [
{
"name": "index",
"request_url": "/index.htm"
}
]
},
{
"name": "images",
"ttl": 12800,
"rules": [
{
"name": "images",
"request_url": "*.png"
}
]
}
],
"restrictions": [
{
"name": "website only",
"rules": [
{
"name": "mywebsite.com",
"referrer": "www.mywebsite.com"
}
]
}
],
"flavor_id": "cdn",
"status": "deployed",
"errors": [],
"links": [
{
"href": "https://global.cdn.api.rackspacecloud.com/v1.0/yourAccountID/services/yourServiceID",
"rel": "self"
},
{ "href": "https://global.cdn.api.rackspacecloud.com/v1.0/yourAccountID/flavors/cdn",
"rel": "flavor"
},
{
"href": "www.mywebsite.com.cdn1.raxcdn.com",
"rel": "access_url"
}
]
}
Updating your Domain Name System#
Look for the access_url
in the links[]
section in the response
in Retrieve a created service for the service that
you created. Make sure that the status
is deployed
.
Go to your DNS (Domain Name System) provider, and create a CNAME record
from your domain (www.mywebsite.com
) to the access_url
returned
(www.mywebsite.com.cdn1.raxcdn.com
).
It may take some time for your DNS change to propagate across the internet. Once this has happened (based on the TTL you have set with your DNS provider), you will be able to access your website via the CDN Edge.
For more information, see Change DNS to enable Rackspace CDN.
Accessing your website#
Open a browser and request your domain www.mywebsite.com
. The
content is now served via the CDN Edge Network.
Purging a cached asset#
After working with the service you created, you might find that you want to purge the current version of an asset that has been cached at the edge node.
Example: cURL purge a cached asset request
curl -i -X DELETE $API_ENDPOINT/v1.0/$TENANT_ID/services/yourServiceID/assets?url=relativeURLofAssettoDelete \
-H "X-Auth-Token: $AUTH_TOKEN" \
-H "Content-type: application/json"
Example: Purge a cached asset response
HTTP/1.1 202 Accepted
Retrieving flavors#
A flavor is a mapping configuration to the Akamai CDN provider. This operation retrieves a list of all available flavors.
Note
Currently, the only flavor available is cdn
.
Example: cURL retrieve flavors request
curl -i -X GET $API_ENDPOINT/v1.0/$TENANT_ID/flavors \
-H "X-Auth-Token: $AUTH_TOKEN" \
-H "Content-type: application/json"
Example: Retrieve flavors response
HTTP/1.1 200 OK
Content-Type: application/json
{
"flavors": [
{
"id": "cdn",
"providers": [
{
"provider": "akamai",
"links": [
{
"href": "http://www.akamai.com",
"rel": "provider_url"
}
]
}
],
"links": [
{
"href": "https://global.cdn.api.rackspacecloud.com/v1.0/yourAccountID/flavors/cdn",
"rel": "self"
}
]
}
]
Deleting a service#
This operation deletes a service.
Example: cURL delete a service request
curl -i -X DELETE $API_ENDPOINT/v1.0/$TENANT_ID/services/yourServiceID \
-H "Content-type: application/json" \
-H "X-Auth-Token: $AUTH_TOKEN" \
-H "Accept: application/json"
Example: Delete a service response
HTTP/1.1 202 Accepted