Skip to main content
Version: 1.0.0

MySQL RESTful API

Function Introduction

This document provides APIs for all MySQL operations, along with parameter references for each API.

Request Domain

Supports the following three domain 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 the environment ID
  • instance is the database instance identifier
  • schema is the database name
  • table is the table name

If using the system database, method 1 is recommended

Integration Guide

To call the following APIs, you need to pass an AccessToken in format Authorization: Bearer <token>. For token acquisition methods, please refer to: https://docs.cloudbase.net/http-api/basic/access-token

Request Encoding

Please perform URL encoding before making requests, for example:

Original request

curl -i -X GET 'https://{{host}}/v1/rdb/rest/course?select=name,position&name=like.%张三%&title=eq.文章标题'

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 Headers and Response Headers

Request HeaderParametersDescriptionExample
AcceptSupports `application/json`, `application/vnd.pgrst.object+json`Controls data return formatAccept: application/json
Content-TypeSupports `application/json`, `application/vnd.pgrst.object+json`ReturnContent-Type: application/json
PreferCharacteristic values that operations depend on- `return=representation` Write operation, returns data body and headers - `return=minimal` Write operation, returns only headers without data body, default type for write operations - `count=exact` Read operation, specifies count calculation - `resolution=merge-duplicates` Upsert operation, merges conflicting items - `resolution=ignore-duplicates` Upsert operation, ignores conflicting itemsPrefer: return=representation
Preference-AppliedPrefer type used in requestResponse information uses Prefer from request, will return corresponding characteristic information, may have default values in certain casesPreference-Applied: return=representation
Content-RangePagination information- When querying with Prefer: count=exact, pagination information like 0-1/2 will be returned, where 0 indicates starting position, 1 indicates offset, and 2 indicates total count (Note: The starting position and offset here are not the meanings of offset and limit keywords in MySQL, but refer to the data position after query, usually used with limit) - When specifying return=representation or return=minimal (default) for write operations, pagination information like *-*/2 will be returned, where 2 indicates the number of affected rowsContent-Range: 0-1/2

Error Codes and HTTP Status Codes

Error CodeHTTP Status CodeDescription
INVALID_PARAM400Invalid request parameter
INVALID_REQUEST400Invalid request content: missing permission fields, SQL execution exceptions, etc.
INVALID_REQUEST406Does not meet single record return constraint
PERMISSION_DENIED401、403Authentication failed: returns 401 if identity authentication fails, returns 403 if authorization fails
RESOURCE_NOT_FOUND404Database instance or table information not found
SYS_ERR500System internal error
OPERATION_FAILED503Failed to establish database connection
RESOURCE_UNAVAILABLE503Database unavailable due to certain reasons

Data Return

  1. For all POST, PATCH, DELETE, request header with Prefer: return=representation indicates there is a response body, absence indicates no response package, only response headers
  2. Response body of POST, PATCH, DELETE is usually JSON array type []. If request header specifies Accept: application/vnd.pgrst.object+json, then JSON object type {} will be returned
  3. If specifying Accept: application/vnd.pgrst.object+json, but the data amount is greater than 1, an error will be reported