Version: 1.0.0
MySQL RESTful API
Feature Introduction
This section provides APIs for calling all mysql operations and parameter references for each API.
Request Domain
It supports the following three domain name access methods:
https://{envId}.api.tcloudbasegateway.com/v1/rdb/rest/{table}https://{envId}.api.tcloudbasegateway.com/v1/rdb/rest/{schema}/{table}https://{envId}.api.tcloudbasegateway.com/v1/rdb/rest/{instance}/{schema}/{table}
- envId is environment id
- instance is the database instance identifier
- schema is database name
- table is table name
If using the system database, method 1 is recommended.
Access Guide
To call the following interfaces, you need to pass an AccessToken in the format Authorization: Bearer <token>. For the method of obtaining a token, refer to: https://docs.cloudbase.net/http-api/basic/access-token
Request Encoding
Before initiating a request, please perform url encoding, for example:
Raw Request
curl -i -X GET 'https://{{host}}/v1/rdb/rest/course?select=name,position&name=like.%John%&title=eq.Article%20Title'Encoded Request
curl -i -X GET 'https://{{host}}/v1/rdb/rest/course?select=name,position&name=like.%%E5%BC%A0%E4%B8%89%&title=eq.%E6%96%87%E7%AB%A0%E6%A0%87%E9%A2%98'
Request and Response Headers
| Request Header | Parameter | Description | Example |
| Accept | Supports `application/json`, `application/vnd.pgrst.object+json` | Controls the data return format | Accept: application/json |
| Content-Type | Supports `application/json`, `application/vnd.pgrst.object+json` | Response | Content-Type: application/json |
| Prefer | Operation-dependent feature value | - `return=representation` write operation, returns the data body and data headers. - `return=minimal` write operation, does not return the data body, only returns the headers, and is the default type for write operations. - `count=exact` read operation, specifies exact counting. - `resolution=merge-duplicates` upsert operation, merges conflicting items. - `resolution=ignore-duplicates` upsert operation, ignores conflicting items. | Prefer: return=representation |
| Preference-Applied | Type of Prefer used in requests | The returned information uses the Prefer from the request, and will return the corresponding feature information accordingly. In some cases, there will be default values. | Preference-Applied: return=representation |
| Content-Range | Pagination Information | - When Prefer: count=exact is specified in a query, pagination information such as 0-1/2 is returned, where 0 represents the start position, 1 represents the offset, and 2 represents the total count. (Note: The start position and offset here do not correspond to the meanings of the offset and limit keywords in mysql, but rather refer to the position in the queried data, typically used in conjunction with limit.) - When return=representation or return=minimal (default) is specified in a write operation, pagination information such as *-*/2 is returned, where 2 represents the number of affected rows. | Content-Range: 0-1/2 |
Error Codes and HTTP Status Codes
| Error Code | HTTP Status Code | Description |
| INVALID_PARAM | 400 | Invalid Request Parameters |
| INVALID_REQUEST | 400 | Invalid request content: missing permission field, SQL execution exception, etc. |
| INVALID_REQUEST | 406 | Violation of single-record return constraint |
| PERMISSION_DENIED | 401,403 | Authentication Failure: Returns 401 for authentication failure, returns 403 for authorization failure |
| RESOURCE_NOT_FOUND | 404 | Database instance or table information not found |
| SYS_ERR | 500 | Internal System Error |
| OPERATION_FAILED | 503 | Failed to establish database connection |
| RESOURCE_UNAVAILABLE | 503 | Database unavailable due to certain reasons |
Data Return
- For all POST, PATCH, DELETE requests alike, including the
Prefer: return=representationheader indicates that there is a response body, while omitting it means no response body, only response headers. - For POST, PATCH, DELETE, the response body is typically of the json array type
[]. If the request header specifiesAccept: application/vnd.pgrst.object+json, then it returns the json object type{} - If
Accept: application/vnd.pgrst.object+jsonis specified but the data quantity exceeds 1, an error will be thrown.