Skip to content

Commit a876727

Browse files
committed
Document REST API
1 parent 268657b commit a876727

File tree

1 file changed

+92
-2
lines changed

1 file changed

+92
-2
lines changed

cloud/docs/rest-api.md

Lines changed: 92 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ This page documents the REST API that every database in Dexie Cloud has.
1111

1212
| [/authorize](#authorize) | Authorize endpoint |
1313
| [/token](#token) | Token endpoint |
14+
| [/all/...](#all-endpoint) | All data endpoint |
15+
| [/my/...](#my-endpoint) | My data endpoint |
16+
| [/public/...](#public-endpoint) | Public data endpoint |
1417

1518
### /authorize
1619

@@ -31,14 +34,101 @@ Request a token for the calling endpoint. This method can be called directly fro
3134
```js
3235
{
3336
grant_type: "client_credentials",
37+
scopes: Array<"ACCESS_DB" | "IMPERSONATE" | "MANAGE_DB" | "GLOBAL_READ" | "GLOBAL_WRITE" | "DELETE_DB">,
3438
client_id: <your client ID>,
3539
client_secret: <your client secret>,
36-
name: <name of user to impersonate>,
37-
email: <email of user to impersonate>
40+
public_key?: <public key> (if a refresh token is needed),
41+
claims: {
42+
sub: <userid>,
43+
email: <email>,
44+
name: <name of user to authenticate>
45+
}
3846
}
3947
```
4048

49+
See a [sample code to call this endpoint to authenticate end users](db.cloud.configure()#example-integrate-custom-authentication).
50+
51+
A client must be given the "IMPERSONATE" scope in order to call this endpoint.
52+
53+
#### scopes
54+
55+
If you use the endpoint to give out tokens for web users, the "ACCESS_DB" scope is the only one to use. If you however, need to generate a token for a server application to use the "/all/..." endpoint, you might want to request a "GLOBAL_READ" or "GLOBAL_WRITE" scope depending on whether the integration should be allowed to read or write to the database within any realm.
56+
57+
### /all/... endpoint
58+
59+
**Get all objects in given table:**
60+
61+
```http
62+
GET /all/<table> HTTP/1.1
63+
Authorization: Bearer <token from /token endpoint (with GLOBAL_READ scope)>
64+
```
65+
66+
**Get all objects in given table and realm:**
67+
68+
```http
69+
GET /all/<table>?realmId=<realmId> HTTP/1.1
70+
Authorization: Bearer <token from /token endpoint (with GLOBAL_READ scope)>
71+
```
72+
73+
**Get all objects in given table with a filter:**
74+
75+
```http
76+
GET /all/<table>?<propName>=<propValue>&<propName2>=<propValue2>&... HTTP/1.1
77+
Authorization: Bearer <token from /token endpoint (with GLOBAL_READ scope)>
78+
```
79+
80+
This request will filter the query to only return matching objects. A concrete example:
81+
82+
```http
83+
GET /all/todoItems?todoListId=xxx HTTP/1.1
84+
Authorization: Bearer <token from /token endpoint (with GLOBAL_READ scope)>
85+
```
86+
87+
*This example would give you all todoItems that has the property todoListId set to "xxx".*
88+
89+
**Get simple object by primary key:**
90+
91+
```http
92+
GET /all/<table>/<primary key> HTTP/1.1
93+
Authorization: Bearer <token from /token endpoint (with GLOBAL_READ scope)>
94+
```
95+
96+
### /my/... endpoint
97+
98+
The /my/... endpoint works exactly like the /all/... endpoint, except that it doesn't search the global database but can only return objects that are accessible for the token subject.
99+
100+
```http
101+
GET /my/<table> HTTP/1.1
102+
Authorization: Bearer <token from /token endpoint (with ACCESS_DB scope)>
103+
```
104+
105+
The token to use should be given out to a certain subject (userId) with the "ACCESS_DB" scope only.
106+
107+
**Example:**
108+
109+
```http
110+
GET /my/todoLists HTTP/1.1
111+
Authorization: Bearer <token from /token endpoint (with ACCESS_DB scope)>
112+
```
113+
114+
*Lists all todoLists that the user has at least readonly access to. Either their own private lists or todo-lists that have been shared to the user.*
115+
116+
### /public/... endpoint
117+
118+
The /public/... endpoint works exactly list the /all/... and /my/... endpoints except that it will only access public data - i.e. data that resides in the public realm "rlm-public". This endpoint does not require authorization.
119+
120+
**Examples:**
121+
122+
```http
123+
GET /public/products HTTP/1.1
124+
```
125+
126+
```http
127+
GET /public/roles HTTP/1.1
128+
```
129+
41130
## See Also
42131

43132
- [Tokens](authentication#tokens)
44133
- [Example auth integration](db.cloud.configure()#example-integrate-custom-authentication)
134+

0 commit comments

Comments
 (0)