Skip to main content

Query data

Query the MySQL database using HTTP RESTful API. For specific interface details, please refer to HTTP API/MySQL database.

Basic Syntax

GET https://your-envId.api.tcloudbasegateway.com/v1/rdb/rest/:table
Authorization: Bearer <access_token>
Content-Type: application/json

💡 Tip: For access_token, refer to Obtain AccessToken

Basic Queries

# Query all records in the film table
curl -X GET 'https://{{host}}/v1/rdb/rest/film' \
-H 'Authorization: Bearer <access_token>'

💡 Note: The returned data includes all fields, with /table?select=* as the default.

Response Example
HTTP/1.1 200 OK
Header:
content-length: 1037
content-type: application/json; charset=utf-8
Body:
[
{
"_openid": "1977683311217119233",
"director": "Chen Kaige",
"duration": 171,
"id": 1,
"release_year": 1993,
"title": "Farewell My Concubine"
},
// ... total 15 records
]

Specify Returned Fields

# Specify Returned Fields for film Table
curl -X GET 'https://{{host}}/v1/rdb/rest/film?select=title,director,release_year' \
-H 'Authorization: Bearer <access_token>'
Response Example
HTTP/1.1 200 OK
Header:
content-length: 1080
content-type: application/json; charset=utf-8
Body:
[
{
"director": "Chen Kaige",
"release_year": 1993,
"title": "Farewell My Concubine"
},
{
"director": "Jiang Wen",
"release_year": 2010,
"title": "Let the Bullets Fly"
}
// ... total 15 records
]

Conditional Queries

# Query movies directed by Christopher Nolan
curl -X GET 'https://{{host}}/v1/rdb/rest/film?director=eq.Christopher Nolan' \
-H 'Authorization: Bearer <access_token>'

# Query movies released after 2000 with a runtime of no more than 120 minutes
curl -X GET 'https://{{host}}/v1/rdb/rest/film?release_year=gte.2000&duration=lt.120' \
-H 'Authorization: Bearer <access_token>'

# Query movies released after 2000, directed by Christopher Nolan or Jiang Wen
curl -X GET 'https://{{host}}/v1/rdb/rest/film?or=(director.eq.Christopher Nolan, director.eq.Jiang Wen)' \
-H 'Authorization: Bearer <access_token>'
Query movies directed by Christopher Nolan
HTTP/1.1 200 OK
Header:
content-length: 260
content-type: application/json; charset=utf-8
Body:
[
{
"_openid": "1977683311217119233",
"director": "Christopher Nolan",
"duration": 169,
"id": 13,
"release_year": 2014,
"title": "Interstellar"
},
{
"_openid": "1977683311217119233",
"director": "Christopher Nolan",
"duration": 148,
"id": 14,
"release_year": 2010,
"title": "Inception"
}
]

Sorting and Pagination

# Query movies released before 2000 and display the top 3 with the longest runtime.
curl -X GET 'https://{{host}}/v1/rdb/rest/film?order=duration.desc&limit=3' \
-H 'Authorization: Bearer <access_token>'
Response Example
HTTP/1.1 200 OK
Header:
content-length: 266
content-type: application/json; charset=utf-8
Body:
[
{
"director": "James Cameron",
"duration": 194,
"release_year": 1997,
"title": "Titanic"
},
{
"director": "Chen Kaige",
"duration": 171,
"release_year": 1993,
"title": "Farewell My Concubine"
},
{
"director": "Frank Darabont",
"duration": 142,
"release_year": 1994,
"title": "The Shawshank Redemption"
}
]

Count Query

# Query movies released after 2000 and their count
curl -X GET 'https://{{host}}/v1/rdb/rest/film?select=*&release_year=gte.2000' \
-H 'Authorization: Bearer <access_token>' \
-H 'Prefer: count=exact'

Request

  • When the Header Prefer: count=exact is specified, the total number of matching data is returned.

Response

  • content-range: 0-9/10 indicates the data range returned by this query, with a total of 10 data entries, where 0 indicates no offset, 9 indicates the index of the last data entry, and 10 indicates the total count.
Response Example
HTTP/1.1 200 OK
Header:
content-length: 853
content-range: 0-9/10
content-type: application/json; charset=utf-8
Body:
[
{
"director": "Jiang Wen",
"duration": 132,
"release_year": 2010,
"title": "Let the Bullets Fly"
},
{
"director": "Guo Fan",
"duration": 125,
"release_year": 2019,
"title": "The Wandering Earth"
},
{
"director": "Wu Jing",
"duration": 123,
"release_year": 2017,
"title": "Wolf Warrior 2"
}

// ... total 10 records
]

Force Return Object Format

Currently, data is always returned in array format. If you need to force return object format, you can specify Header Accept: application/vnd.pgrst.object+json.

⚠️ Warning: This method can only be used when exactly one record is returned. You may add limit=1 to restrict the number of returned records.

curl -i -X GET 'http://{{host}}/v1/rdb/rest/v1/film?select=*&id=eq.1&limit=1' \
-H 'Authorization: Bearer <access_token>' \
-H 'Accept: application/vnd.pgrst.object+json'
Response Example
HTTP/1.1 200 OK
Header:
content-length: 121
content-type: application/vnd.pgrst.object+json
Body:
{
"director": "Chen Kaige",
"duration": 171,
"id": 1,
"release_year": 1993,
"title": "Farewell My Concubine",
"_openid": "1977683311217119233"
}

Literal Query

MySQL allows creating tables and fields with special characters such as spaces. In such cases, url requests require literal handling (using double quotes) to avoid conflicts with special characters and keywords.

Assume the following table structure:

  • Table Name: my table
  • Field Name: full name, email address
curl -i -X 'GET http://{{host}}/v1/rdb/rest/my table?select="full name","email address"' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer <access_token>' \
Response Example
HTTP/1.1 200 OK
Header:
content-length: 61
content-type: application/json; charset=utf-8
Body:
[
{
"email address": "john@example.com",
"full name": "John Doe"
}
]

Operators

OperatorDescriptionExample
eqEqual?id=eq.1
neqNot equal?id=neq.1
gtGreater than?age=gt.18
gteGreater than or equal?age=gte.18
ltLess than?age=lt.35
lteLess than or equal?age=lte.35
likePattern matching?name=like.%value%
inIn?id=in.[1,2,3]
isis null?age=is.null
andLogical AND?and=(age.gt.18,age.lt.35)
orLogical OR?or=(id.eq.1,name.like.%value%)
notLogical NOT?age=not.eq.18

Supported Logical Operators

OperatorDescriptionMysql Equivalent OperatorExample
andLogical ANDand/table?id=eq.1&age=gt.18 and /table?select=*&and=(age.gt.18,age.lt.35)
orLogical ORor/table?select=*&or=(id.eq.1,name.like.%value%)
notLogical NOTnot/table?select=*&age=not.eq.18&gender=not.is.null&isTrue=not.is.true