Swift REST API Example
Last post I explained REST interfaces, and promised to use a Swift REST API as an example. This application programming interface (API) supports the following operations.
1) Swift REST API Authorization
GET AUTHORIZATION
This operation is used to obtain an authorization token and URL for agiven user login and password. This token and URL are then used in any subsequent operations.
- URL Data: None.
- Required Request Headers:
- X-Auth-User = user login.
- X-Auth-Key = user password.
- Optional Request Headers: None.
- Parameters: None.
- Response Headers:
- Content-Length = always zero.
- Date = current date.
- X-Auth-Token = authorization token, input for subsequent operations.
- X-Storage-Token = storage token, input for subsequent operations.
- X-Storage-Url = storage URL, input for subsequent operations.
- HTTP Data: None.
2) Swift REST API Account
DELETE ACCOUNT
Mark an account as deleted. Swift REST API will clean up the account as time permits.
- URL Data: None.
- Required Request Headers:
- X-Auth-Token = authorization token.
- Optional Request Headers: None.
- Parameters: None.
- Response Headers:
- Content-Length = always zero.
- Content-Type = http data content type.
- Date = current date.
- HTTP Data: None.
GET ACCOUNT
Get the list of containers in an account.
- URL Data: None.
- Required Request Headers:
- X-Auth-Token = authorization token.
- Optional Request Headers: None.
- Parameters:
- format=type : return http data in “json” or “xml” format.
- limit=number : limit the number of returned containers.
- marker=filter : provide a filter. The returned list of containers will start after “filter”.
- Response Headers:
- Accept-Ranges = always “bytes”. This header will eventually comply with the http “range” header.
- Content-Length = the number of bytes in http data.
- Content-Type = http data content type.
- Date = current date.
- X-Account-Bytes-Used = the number of bytes used in the account. Keep in mind that this field is updated in a lazy fashion.
- X-Account-Container-Count = the number of containers in the account.
- X-Account-Object-Count = the number of objects in the account. Keep in mind that this field is updated in a lazy fashion.
- HTTP Data: The list of containers for the account.
HEAD ACCOUNT
Get account statistics.
- URL Data: None.
- Required Request Headers:
- X-Auth-Token = authorization token.
- Optional Request Headers: None.
- Parameters: None.
- Response Headers:
- Accept-Ranges = always “bytes”. This header will eventually comply with the http “range” header.
- Content-Length = always zero.
- Content-Type = http data content type.
- Date = current date.
- X-Account-Bytes-Used = the number of bytes used in the account. Keep in mind that this field is updated in a lazy fashion.
- X-Account-Container-Count = the number of containers in the account.
- X-Account-Object-Count = the number of objects in the account. Keep in mind that this field is updated in a lazy fashion.
- HTTP Data: None.
POST ACCOUNT
- Post meta-data to an account.
- URL Data: None.
- Required Request Headers:
- X-Auth-Token = authorization token.
- Optional Request Headers:
- X-Account-Meta-* = the user can create a account meta-data header. Such headers are of the form: “key value”. The resulting account header will be: “X-Account-Meta-key: value”
- Parameters: None.
- Response Headers:
- Content-Length = always zero.
- Content-Type = http data content type.
- Date = current date.
- HTTP Data: None.
PUT ACCOUNT
Create an account.
- URL Data: None.
- Required Request Headers:
- X-Auth-Token = authorization token.
- Optional Request Headers:
- X-Account-Meta-* = the user can create a account meta-data header. Such headers are of the form: “key value”. The resulting account header will be: “X-Account-Meta-key: value”
- Parameters: None.
- Response Headers:
- Content-Length = always zero.
- Content-Type = http data content type.
- Date = current date.
- HTTP Data: None.
3) Swift REST API Container
DELETE CONTAINER
Mark a container as deleted. Swift will clean up the container as time permits.
- URL Data: Container name.
- Required Request Headers:
- X-Auth-Token = authorization token.
- Optional Request Headers: None.
- Parameters: None.
- Response Headers:
- Content-Length = always zero.
- Content-Type = http data content type.
- Date = current date.
- HTTP Data: None.
GET CONTAINER
Get the list of objects in a container.