# API Calls

Codavel's API allows the following remote configuration calls:

Pre-Populate Cache

Purge Cache

# Pre-Populate Cache

Codavel's CDN architecture can preveniently populate your deployment's cache with some of your highly requested content, significantly reducing your users waiting time.

# Cache data pre-fetching

Codavel's API provides a simple way for you to pre-cache specific content by performing the following curl command:

curl \
    --request POST \
    --header 'content-type: application/json' \
    --header 'secret: <deployment_secret>' \ 
    --data @requestsFile.json \
    https://api.cloud.codavel.com/deployment/prepopulate/<your_deployment_id>
1
2
3
4
5
6

in which requestsFile.json is a json file where you specify the requests whose content will be pre-fetched, using the following syntax:

requestsFile.json:

{
    "urls": [
    {
        "url":"https://www.example-content-url.com",
            "headers": [
            {"header 1":"value 1"},
            {"header 2":"Value 2"},
            ...
            ]
    },
    {
        "url":"http://www.another-example-content-url.com",
        "headers": [
        {"header 1":"value 1"},
        {"header 2":"Value 2"},
        ...
        ]
    },
    ...
    ]
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

# Output:

If no errors occur, the received response should look something like this:

"status": "Sucessful request"
1

Important: Any valid request given to this endpoint will overwrite any previous fetched content. If you wish to add or correct any request, make sure you also include any previous requests you would want to maintain in your cache.

# Error handling:

If an error occurs during the pre-populating process you should receive an error message, giving you a bit more insight on what went wrong.

Some of the more typical error messages, and possible fixes are:

  • # "error": "Not authorized":

The authentication process for your deployment failed. Please make sure that the "secret: <deployment_secret>" header is correct, and that the secret used is for your deployment.

  • # "error": "Bad request format":

The parsing process for your pre-populate request failed. Please unsure that your requestsFile.json file is structured as shown above.

  • # "error": "Request list too large - max allowed is 1MB":

Your requestsFile.json size exceeds the maximum allowed.

  • # "error": "Only HTTP and HTTPS protocol are allowed":

Your pre-populate request use other protocols besides HTTP(S).

# Purge Cache

Codavel's CDN architecture allows you to purge previously cached content from your deployment's cache, reducing the amount of space stale content occupies in your cache and forcefully refresh content the next time one of your users demands it.

# Cache data purging

Codavel's API provides a simple way for you to purge specific content by performing the following curl command:

curl \
    --request POST \
    --header 'content-type: application/json' \
    --header 'secret: <deployment_secret>' \ 
    --data @requestsFile.json \
    https://api.cloud.codavel.com/deployment/purge/<your_deployment_id>
1
2
3
4
5
6

in which requestsFile.json is a json file where you specify the content to be purged, using the following syntax:

requestsFile.json:

{
    "contentToPurge":[
        {
            "type":"[BASENAME]",
            "content": "example-image.jpeg"
        },
        {
            "type":"[FILENAME]",
            "content": "example-image"
        },
        {
            "type":"[EXTENSION]",
            "content": "jpeg"
        },
        {
            "type":"[MIMETYPE]",
            "content": "image/jpeg"
        }
    ]
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

Where each entry in the requestsFile.json is composed of:

  • type tag, specifying the filter for the content to be purged:

    • [ALL] Purges all content from the cache, ignoring the content associated tag:
    "type":"[ALL]",
    "content": ""
    
    1
    2

    Important: content tag is still mandatory.

    • [FULL_URL] Purges content pointed to by the given full url:
    "type":"[FULL_URL]",
    "content": "/content/example-image.jpg"
    
    1
    2
    • [BASENAME] Purges content with the given base name (including file extensions):
    "type":"[BASENAME]",
    "content": "example-image.jpg"
    
    1
    2
    • [FILENAME] Purges content with the given file name (excluding file extensions):
    "type":"[FILENAME]",
    "content": "example-image"
    
    1
    2
    • [EXTENSION] Purges content with the given extension:
    "type":"[EXTENSION]",
    "content": "jpeg"
    
    1
    2
    • [MIMETYPE] Purges content with the given MIME type:
    "type":"[MIMETYPE]",
    "content": "image/jpeg"
    
    1
    2

# Output:

If no errors occur, the received response should look something like this:

"status": "Sucessful request"
1

Important: Codavel's CDN architecture will purge the selected content as soon as possible, as such make sure you specified the correct content to be purged.

# Error handling:

If an error occurs during the purge process you should receive an error message, giving you a bit more insight on what went wrong.

Some of the more typical error messages, and possible fixes are:

  • # "error": "Not authorized":

The authentication process for your deployment failed. Please make sure that the "secret: <deployment_secret>" header is correct, and that the secret used is for your deployment.

  • # "error": "Bad request format":

The parsing process for your purge request failed. Please unsure that your requestsFile.json file is structured as shown above.

  • # "error": "Request list too large - max allowed is 1MB":

Your requestsFile.json size exceeds the maximum allowed.