PostgreSQL HTTP API
Function Introduction
The Data API of CloudBase PostgreSQL database is based on the open-source PostgREST. For more documentation, please refer to the official PostgREST documentation.
Currently the REST API only supports the public schema: you can only access tables, views, and functions in the public schema, and cannot access or switch to other schemas (such as auth or storage).
To read or write data outside the public schema, use Execute SQL statements or the SQL editor in the console instead.
Request Domain
The request URL format is: https://{envId}.api.tcloudbasegateway.com/v1/rdb/rest/{table}
- envId is the environment ID
- table is the table name, which must be in the
publicschema
Integration Guide
To call the following APIs, you need to pass an AccessToken in format Authorization: Bearer <token>. For how to obtain the Access token, refer to the documentation.
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 Header | Parameters | Description | Example |
| Accept | Supports application/json, application/vnd.pgrst.object+json | Controls data return format | Accept: application/json |
| Content-Type | Supports application/json, application/vnd.pgrst.object+json | Return | Content-Type: application/json |
| Prefer | Characteristic values that operations depend on |
| Prefer: return=representation |
| Preference-Applied | Prefer type used in request | Response information uses Prefer from request, will return corresponding characteristic information, may have default values in certain cases | Preference-Applied: return=representation |
| Content-Range | Pagination information |
| Content-Range: 0-1/2 |
Error Codes and HTTP Status Codes
| Error Code | HTTP Status Code | Description |
| INVALID_PARAM | 400 | Invalid request parameter |
| INVALID_REQUEST | 400 | Invalid request content: missing permission fields, SQL execution exceptions, etc. |
| INVALID_REQUEST | 406 | Does not meet single record return constraint |
| PERMISSION_DENIED | 401、403 | Authentication failed: returns 401 if identity authentication fails, returns 403 if authorization fails |
| RESOURCE_NOT_FOUND | 404 | Database instance or table information not found |
| SYS_ERR | 500 | System internal 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, request header with
Prefer: return=representationindicates there is a response body, absence indicates no response package, only response headers - Response body of POST, PATCH, DELETE is usually JSON array type
[]. If request header specifiesAccept: application/vnd.pgrst.object+json, then JSON object type{}will be returned - If specifying
Accept: application/vnd.pgrst.object+json, but the data amount is greater than 1, an error will be reported