A CDN API provides users the flexibility to integrate their zones and other KeyCDN features directly into their applications. This article covers some of the use cases, features, and integration methods of using a CDN API.
CDN API Use Cases
There are a couple of use-cases where using a CDN API can provide some major benefits. These include:
- Automation: Having the ability to integrate an API into your existing application can help improve automation and thus save you time from performing mundane tasks.
- Reselling: Facilitating the addition of a new CDN zone with the API each time a customer signs up for a service (e.g. a hosting provider) can help enhance the customer’s experience and is more convenient for the reseller.
How to Get Started
To get started with the CDN API, login to your KeyCDN dashboard and navigate to Account Settings > Authentication. Here you will find your secret CDN API key which you will need for authentication purposes. At this point, head over to the KeyCDN API page where you will find a list of available API calls. There are various example requests and responses listed to provide users with the ability to perform various tasks while also showing what to expect when an API call is run.
The KeyCDN API can be used in combination with developer tools including the ones mentioned below.
Postman provides users the ability to integrate with your current workflow allowing you to explore, build, and test APIs in the way that works best for you. Developers can use this tool to test their application in combination with the CDN API calls to ensure everything is working as expected.
cURL is a tool used to transfer data to and from a server. With the KeyCDN API, you can run cURL commands directly from your terminal or command line to retrieved desired information. Anything from the creation of new zones, zonealiases, zonereferrers, generation of reports, etc. can be achieved through running simple commands. For example, running a cURL command to list all of your zones would resemble (without the square brackets around your CDN API key).
curl "https://api.keycdn.com/zones.json" -u [apikey]:
CDN API Wrappers
KeyCDN offers various API wrappers to give users the ability to integrate directly into the application they are working on. This helps improve automation as the user is not required to perform tasks from the KeyCDN dashboard but can rather can generate reports, purge the cache, add zones, etc. directly from the application. KeyCDN currently offers three CDN API wrappers:
Using a CDN API With Gulp and Grunt
Gulp and Grunt are both task/build runners for development. They help automate some of the more repetitive tasks involved in the development workflow such as compressing CSS / JS files, image optimization, compiling Sass files and more. KeyCDN offers a plugin for both task runners to enable interaction with the CDN API.
Purging and Stats
The CDN API allows users to quickly purge an entire zone or section of a zone as well as offer statistics within a given time range. There are currently three ways to perform a purge request via the KeyCDN API.
- Purge Zone Cache – This method purges the entire zone’s cache.
- Purge Zone URL – This method purges the cache for the specified urls.
- Purge Zone Tag – This method purges the cache for the specified tags.
CDN Statistics are also available via the API. Information such as traffic, storage, status, and credit statistics are all able via reports. Parameters can be defined within your API calls to retrieve specific information such as the zone ID, start time, end time, interval, and type.
Overall, using a CDN API can help improve efficiency and allow for seamless integrate between your applications. For more information about KeyCDN’s API, visit our API Documentation page.