Skip to main content
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:

  1. https://{envId}.api.tcloudbasegateway.com/v1/rdb/rest/{table}
  2. https://{envId}.api.tcloudbasegateway.com/v1/rdb/rest/{schema}/{table}
  3. 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 HeaderParameterDescriptionExample
AcceptSupports `application/json`, `application/vnd.pgrst.object+json`Controls the data return formatAccept: application/json
Content-TypeSupports `application/json`, `application/vnd.pgrst.object+json`ResponseContent-Type: application/json
PreferOperation-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-AppliedType of Prefer used in requestsThe 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-RangePagination 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 CodeHTTP Status CodeDescription
INVALID_PARAM400Invalid Request Parameters
INVALID_REQUEST400Invalid request content: missing permission field, SQL execution exception, etc.
INVALID_REQUEST406Violation of single-record return constraint
PERMISSION_DENIED401,403Authentication Failure: Returns 401 for authentication failure, returns 403 for authorization failure
RESOURCE_NOT_FOUND404Database instance or table information not found
SYS_ERR500Internal System Error
OPERATION_FAILED503Failed to establish database connection
RESOURCE_UNAVAILABLE503Database unavailable due to certain reasons

Data Return

  1. For all POST, PATCH, DELETE requests alike, including the Prefer: return=representation header indicates that there is a response body, while omitting it means no response body, only response headers.
  2. For POST, PATCH, DELETE, the response body is typically of the json array type []. If the request header specifies Accept: application/vnd.pgrst.object+json, then it returns the json object type {}
  3. If Accept: application/vnd.pgrst.object+json is specified but the data quantity exceeds 1, an error will be thrown.