api-dock 0.4.6__tar.gz → 0.4.8__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {api_dock-0.4.6 → api_dock-0.4.8}/PKG-INFO +186 -175
- {api_dock-0.4.6 → api_dock-0.4.8}/README.md +185 -174
- {api_dock-0.4.6 → api_dock-0.4.8}/api_dock/config.py +0 -21
- {api_dock-0.4.6 → api_dock-0.4.8}/api_dock/fast_api.py +0 -7
- {api_dock-0.4.6 → api_dock-0.4.8}/api_dock/flask_api.py +0 -14
- {api_dock-0.4.6 → api_dock-0.4.8}/api_dock/route_mapper.py +4 -32
- {api_dock-0.4.6 → api_dock-0.4.8}/api_dock/sql_builder.py +0 -12
- {api_dock-0.4.6 → api_dock-0.4.8}/api_dock/storage_auth.py +0 -2
- {api_dock-0.4.6 → api_dock-0.4.8}/api_dock.egg-info/PKG-INFO +186 -175
- {api_dock-0.4.6 → api_dock-0.4.8}/pyproject.toml +1 -1
- {api_dock-0.4.6 → api_dock-0.4.8}/LICENSE.md +0 -0
- {api_dock-0.4.6 → api_dock-0.4.8}/api_dock/__init__.py +0 -0
- {api_dock-0.4.6 → api_dock-0.4.8}/api_dock/auth.py +0 -0
- {api_dock-0.4.6 → api_dock-0.4.8}/api_dock/cli.py +0 -0
- {api_dock-0.4.6 → api_dock-0.4.8}/api_dock/config_discovery.py +0 -0
- {api_dock-0.4.6 → api_dock-0.4.8}/api_dock/database_config.py +0 -0
- {api_dock-0.4.6 → api_dock-0.4.8}/api_dock/encryption.py +0 -0
- {api_dock-0.4.6 → api_dock-0.4.8}/api_dock.egg-info/SOURCES.txt +0 -0
- {api_dock-0.4.6 → api_dock-0.4.8}/api_dock.egg-info/dependency_links.txt +0 -0
- {api_dock-0.4.6 → api_dock-0.4.8}/api_dock.egg-info/entry_points.txt +0 -0
- {api_dock-0.4.6 → api_dock-0.4.8}/api_dock.egg-info/requires.txt +0 -0
- {api_dock-0.4.6 → api_dock-0.4.8}/api_dock.egg-info/top_level.txt +0 -0
- {api_dock-0.4.6 → api_dock-0.4.8}/config/config.yaml +0 -0
- {api_dock-0.4.6 → api_dock-0.4.8}/config/databases/db_example.yaml +0 -0
- {api_dock-0.4.6 → api_dock-0.4.8}/config/databases/test_users.yaml +0 -0
- {api_dock-0.4.6 → api_dock-0.4.8}/config/remotes/remote_with_allowed_routes.yaml +0 -0
- {api_dock-0.4.6 → api_dock-0.4.8}/config/remotes/remote_with_custom_mapping.yaml +0 -0
- {api_dock-0.4.6 → api_dock-0.4.8}/config/remotes/remote_with_restrictions.yaml +0 -0
- {api_dock-0.4.6 → api_dock-0.4.8}/config/remotes/remote_with_wildcards.yaml +0 -0
- {api_dock-0.4.6 → api_dock-0.4.8}/setup.cfg +0 -0
- {api_dock-0.4.6 → api_dock-0.4.8}/tests/test_config_syntax.py +0 -0
- {api_dock-0.4.6 → api_dock-0.4.8}/tests/test_curl_fixes.py +0 -0
- {api_dock-0.4.6 → api_dock-0.4.8}/tests/test_restrictions.py +0 -0
- {api_dock-0.4.6 → api_dock-0.4.8}/tests/test_root_endpoint.py +0 -0
- {api_dock-0.4.6 → api_dock-0.4.8}/tests/test_sql_append.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: api_dock
|
|
3
|
-
Version: 0.4.
|
|
3
|
+
Version: 0.4.8
|
|
4
4
|
Summary: A flexible API gateway that allows you to proxy requests to multiple remote APIs and Databases
|
|
5
5
|
Author-email: Brookie Guzder-Williams <bguzder-williams@berkeley.edu>
|
|
6
6
|
License: BSd 3-clause
|
|
@@ -39,21 +39,21 @@ Dynamic: license-file
|
|
|
39
39
|
|
|
40
40
|
# API Dock
|
|
41
41
|
|
|
42
|
-
API Dock
|
|
42
|
+
API Dock allows users to quickly build API-s that proxy requests to multiple remote APIs and Databases through a single endpoint. Configuration is handled with simple YAML files. Using API Dock's CLI, an API can easily be launched as a FastAPI or Flask app, or integrated into any existing python based API.
|
|
43
43
|
|
|
44
44
|
## Table of Contents
|
|
45
45
|
|
|
46
|
-
- [Features](#features)
|
|
47
46
|
- [Install](#install)
|
|
48
|
-
- [
|
|
49
|
-
- [
|
|
50
|
-
|
|
51
|
-
- [
|
|
52
|
-
- [Configuration and Syntax](#configuration-and-syntax)
|
|
53
|
-
- [Main Configuration](#main-configuration-api_dock_configconfigyaml)
|
|
47
|
+
- [File Structure](#file-structure)
|
|
48
|
+
- [Simple Example](#simple-example)
|
|
49
|
+
- [Configuration Syntax](#configuration-syntax)
|
|
50
|
+
- [Main Configuration](#main-configuration)
|
|
54
51
|
- [Remote Configurations](#remote-configurations)
|
|
55
52
|
- [SQL Database Support](#sql-database-support)
|
|
56
53
|
- [URL Query Parameters](#url-query-parameters)
|
|
54
|
+
- [CLI](#cli)
|
|
55
|
+
- [Commands](#commands)
|
|
56
|
+
- [Examples](#examples)
|
|
57
57
|
- [Cookies and Authentication](#cookies-and-authentication)
|
|
58
58
|
- [Using RouteMapper in Your Own Projects](#using-routemapper-in-your-own-projects)
|
|
59
59
|
- [Basic Integration](#basic-integration)
|
|
@@ -83,12 +83,53 @@ pip install api_dock
|
|
|
83
83
|
conda install -c conda-forge api_dock
|
|
84
84
|
```
|
|
85
85
|
|
|
86
|
-
|
|
86
|
+
---
|
|
87
|
+
|
|
88
|
+
## File Structure
|
|
89
|
+
|
|
90
|
+
The main configuration files are stored in the top level of the CWD's `api_dock_config/` directory. Multiple configurations, with both versioned and unversioned remote-apis and databases are possible.
|
|
91
|
+
|
|
92
|
+
Here is an example:
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
api_dock_config
|
|
96
|
+
├── config.yaml # The default main-config file
|
|
97
|
+
├── databases
|
|
98
|
+
│ ├── unversioned_db.yaml # Database config without versioning
|
|
99
|
+
│ └── versioned_db # Folder containing database configs for different versions
|
|
100
|
+
│ ├── 0.1.yaml
|
|
101
|
+
│ ├── 0.5.yaml
|
|
102
|
+
│ └── 1.1.yaml
|
|
103
|
+
└── remotes
|
|
104
|
+
├── service1.yaml # Remote-Api config without versioning
|
|
105
|
+
├── service2.yaml # Remote-Api config without versioning
|
|
106
|
+
└── versioned_service # Folder containing remote-api configs for different versions
|
|
107
|
+
├── 0.1.yaml
|
|
108
|
+
├── 0.2.yaml
|
|
109
|
+
└── 0.3.yaml
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
By default api-dock expects there to be one called `config.yaml`, however configs with different names (such as `config_v2`) can be added and launched as shown in the CLI Examples section.
|
|
113
|
+
|
|
114
|
+
---
|
|
115
|
+
|
|
116
|
+
## Simple Example
|
|
87
117
|
|
|
88
118
|
Configuration consists of a global config (`api_dock_config/config.yaml`), as well as a config file for each remote-api or database you'd like to proxy.
|
|
89
119
|
|
|
90
120
|
Here is a simple example of a configuration serving a single remote-api and database:
|
|
91
121
|
|
|
122
|
+
```bash
|
|
123
|
+
api_dock_config
|
|
124
|
+
├── config.yaml
|
|
125
|
+
├── databases
|
|
126
|
+
│ └── db_example
|
|
127
|
+
│ ├── 0.1.yaml
|
|
128
|
+
│ └── 0.5.yaml
|
|
129
|
+
└── remotes
|
|
130
|
+
└── service1.yaml
|
|
131
|
+
```
|
|
132
|
+
|
|
92
133
|
```yaml
|
|
93
134
|
# api_dock_config/config.yaml
|
|
94
135
|
name: "My API Dock"
|
|
@@ -105,22 +146,22 @@ databases:
|
|
|
105
146
|
```
|
|
106
147
|
|
|
107
148
|
```yaml
|
|
108
|
-
# api_dock_config/remotes/service1
|
|
149
|
+
# api_dock_config/remotes/service1.yaml
|
|
109
150
|
name: service1
|
|
110
|
-
description: "Service1
|
|
111
|
-
url: https://
|
|
151
|
+
description: "API Service1"
|
|
152
|
+
url: https://remote.api.com
|
|
112
153
|
```
|
|
113
154
|
|
|
114
155
|
```yaml
|
|
115
|
-
# api_dock_config/databases/db_example/0.
|
|
156
|
+
# api_dock_config/databases/db_example/0.5.yaml
|
|
116
157
|
name: db_example
|
|
117
|
-
description: "Example DB Version 0.
|
|
158
|
+
description: "Example DB Version 0.5"
|
|
118
159
|
authors:
|
|
119
160
|
- "API Team"
|
|
120
161
|
|
|
121
162
|
tables:
|
|
122
163
|
users:
|
|
123
|
-
uri: s3://path/to/users-database/
|
|
164
|
+
uri: s3://path/to/users-database/partitioned-db_example/**/*.parquet
|
|
124
165
|
region: us-west-2
|
|
125
166
|
|
|
126
167
|
routes:
|
|
@@ -131,115 +172,55 @@ routes:
|
|
|
131
172
|
sql: SELECT [[users]].* FROM [[users]] WHERE [[users]].user_id = {{user_id}}
|
|
132
173
|
```
|
|
133
174
|
|
|
134
|
-
|
|
175
|
+
Note: the use of wildcards `**/*` for the partioned parquet file. If there was no partitioning you would give the direct uri `s3://path/to/users-database/db_example.parquet`.
|
|
176
|
+
|
|
177
|
+
This will create an "api-dock" with the following endpoints.
|
|
135
178
|
|
|
136
179
|
```
|
|
137
|
-
- `/service1
|
|
138
|
-
- `/db_example/0.
|
|
139
|
-
- `/db_example/0.
|
|
180
|
+
- `/service1/*`: maps directly onto `https://remote.api.com/*`
|
|
181
|
+
- `/db_example/0.5/users`: queries all users in the "users-database"
|
|
182
|
+
- `/db_example/0.5/users/{user_id}`: queries all users in the "users-database" with `user.user_id = user_id`
|
|
140
183
|
```
|
|
141
184
|
|
|
142
|
-
Note: the filename is being used for versioning. An endpoint with "latest" is also generated that will numerically order versions by name and serve the most recent version.
|
|
143
|
-
`/
|
|
185
|
+
Note: the filename is being used for versioning. An endpoint with "latest" is also generated that will numerically order versions by name and serve the most recent version. In this example, the route
|
|
186
|
+
`/db_example/0.1` uses the config in `/db_example/0.1.yaml`, while both `/db_example/0.5` and `/db_example/latest` will use `/db_example/0.5.yaml`, the most recent version in the `/db_example` folder.
|
|
144
187
|
|
|
145
188
|
These basic configurations can be expanded to include a number of use cases: [restricting routes/methods](#route-restrictions), [custom mapping of remote-api routes](#custom-route-mapping), [accepting query parameters to filter data](#query-parameter-filtering), [limiting and sorting results](#sorting-and-pagination), [authentication](#authentication-setup), and [accessing data stored in cookies](#cookie-access).
|
|
146
189
|
|
|
147
190
|
---
|
|
148
191
|
|
|
149
|
-
#
|
|
150
|
-
|
|
151
|
-
## Commands
|
|
152
|
-
|
|
153
|
-
API Dock provides a modern Click-based CLI:
|
|
154
|
-
|
|
155
|
-
- **pixi run api-dock** (default): List all available configurations
|
|
156
|
-
- **pixi run api-dock init [--force]**: Initialize `api_dock_config/` directory with default configs
|
|
157
|
-
- **pixi run api-dock start [config_name]**: Start API Dock server with optional config name
|
|
158
|
-
- **pixi run api-dock describe [config_name]**: Display formatted configuration with expanded SQL queries
|
|
159
|
-
|
|
160
|
-
**Note**: All commands shown use `pixi run` for the pixi environment. If not using pixi, drop the `pixi run` prefix (e.g., `api-dock start` instead of `pixi run api-dock start`).
|
|
192
|
+
# Configuration Syntax
|
|
161
193
|
|
|
194
|
+
## Main Configuration
|
|
162
195
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
```bash
|
|
166
|
-
# Initialize local configuration directory
|
|
167
|
-
pixi run api-dock init
|
|
168
|
-
|
|
169
|
-
# List available configurations, and available commands
|
|
170
|
-
pixi run api-dock
|
|
171
|
-
|
|
172
|
-
# Start API server
|
|
173
|
-
# - default configuration (api_dock_config/config.yaml) with FastAPI
|
|
174
|
-
pixi run api-dock start
|
|
175
|
-
# - default configuration with Flask (backbone options: fastapi (default) or flask)
|
|
176
|
-
pixi run api-dock start --backbone flask
|
|
177
|
-
# - specify with host and/or port
|
|
178
|
-
pixi run api-dock start --host 0.0.0.0 --port 9000
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
# these commands also work for alternative configurations (example: api_dock_config/config_v2.yaml)
|
|
182
|
-
pixi run api-dock start config_v2
|
|
183
|
-
pixi run api-dock describe config_v2
|
|
184
|
-
```
|
|
185
|
-
|
|
186
|
-
**For more details**, see the [Configuration Wiki](https://github.com/yourusername/api_dock/wiki/Configuration).
|
|
187
|
-
|
|
188
|
-
---
|
|
189
|
-
|
|
190
|
-
# CONFIGURATION AND SYNTAX
|
|
191
|
-
|
|
192
|
-
Assume our file structure is:
|
|
193
|
-
|
|
194
|
-
```bash
|
|
195
|
-
api_dock_config
|
|
196
|
-
├── config.yaml
|
|
197
|
-
├── config_v2.yaml
|
|
198
|
-
├── databases
|
|
199
|
-
│ ├── analytics_db.yaml
|
|
200
|
-
│ └── versioned_db
|
|
201
|
-
│ ├── 0.1.yaml
|
|
202
|
-
│ ├── 0.5.yaml
|
|
203
|
-
│ └── 1.1.yaml
|
|
204
|
-
└── remotes
|
|
205
|
-
├── service1.yaml
|
|
206
|
-
├── service2.yaml
|
|
207
|
-
└── versioned_service
|
|
208
|
-
├── 0.1.yaml
|
|
209
|
-
├── 0.2.yaml
|
|
210
|
-
└── 0.3.yaml
|
|
211
|
-
```
|
|
212
|
-
|
|
213
|
-
---
|
|
214
|
-
|
|
215
|
-
## Main Configuration (`api_dock_config/config.yaml`)
|
|
216
|
-
|
|
217
|
-
The main configuration files are stored in the top level of the CWD's `api_dock_config/` directory. By default api-dock expects there to be one called `config.yaml`, however configs with different names (such as `config_v2`) can be added and launched as shown in the CLI Examples section.
|
|
196
|
+
The main configuration file tells api-dock which remote-api and database configuration files to connect to. Additionally there are adds meta-data (returned by the base-api-route) and optional-settings:
|
|
218
197
|
|
|
219
198
|
```yaml
|
|
220
199
|
# api_dock_config/config.yaml
|
|
221
|
-
name: "My API Dock"
|
|
222
|
-
description: "API proxy for multiple services"
|
|
223
|
-
authors: ["Your Name"]
|
|
224
200
|
|
|
225
|
-
#
|
|
201
|
+
# meta-data: this is returned as the base api-route by default
|
|
202
|
+
name: # API Name
|
|
203
|
+
description: # Description of API
|
|
204
|
+
authors: # list of Authors
|
|
205
|
+
|
|
206
|
+
# sql-databases to query
|
|
207
|
+
databases:
|
|
208
|
+
- "unversioned_db" # adds database configuration in "api_dock_config/databases/unversioned_db.yaml"
|
|
209
|
+
- "versioned_db" # adds database configurations in "api_dock_config/databases/versioned_db/"
|
|
210
|
+
|
|
211
|
+
# remote APIs to proxy
|
|
226
212
|
remotes:
|
|
227
213
|
- "service1" # add configuration in "api_dock_config/remotes/service1.yaml"
|
|
228
214
|
- "service2" # add configuration in "api_dock_config/remotes/service2.yaml"
|
|
229
215
|
- "versioned_service" # add configurations in versions in "api_dock_config/remotes/versioned_service/"
|
|
230
216
|
|
|
231
|
-
# SQL databases to query
|
|
232
|
-
databases:
|
|
233
|
-
- "analytics_db" # adds database configuration in "api_dock_config/databases/analytics_db.yaml"
|
|
234
|
-
- "versioned_db" # adds database configurations in "api_dock_config/databases/versioned_db/"
|
|
235
|
-
|
|
236
217
|
# Optional HTTP behavior settings
|
|
237
218
|
settings:
|
|
238
219
|
add_trailing_slash: true # Auto-add trailing slash to paths (default: true)
|
|
239
220
|
follow_protocol_downgrades: false # Allow HTTPS->HTTP redirects (default: false)
|
|
240
221
|
```
|
|
241
222
|
|
|
242
|
-
### Settings
|
|
223
|
+
### HTTP behavior Settings
|
|
243
224
|
|
|
244
225
|
The optional `settings` section controls HTTP behavior:
|
|
245
226
|
|
|
@@ -247,38 +228,30 @@ The optional `settings` section controls HTTP behavior:
|
|
|
247
228
|
|
|
248
229
|
- **`follow_protocol_downgrades`** (default: `false`): Control how HTTP redirects are handled. When `false` (recommended), HTTPS→HTTP redirects are blocked for security. When `true`, allows following redirects that downgrade from HTTPS to HTTP (not recommended for production).
|
|
249
230
|
|
|
250
|
-
**Example:**
|
|
251
|
-
```yaml
|
|
252
|
-
settings:
|
|
253
|
-
add_trailing_slash: true # Avoids redirects by adding trailing slash
|
|
254
|
-
follow_protocol_downgrades: false # Blocks insecure HTTPS->HTTP redirects
|
|
255
|
-
```
|
|
256
|
-
|
|
257
231
|
---
|
|
258
232
|
|
|
259
233
|
## Remote Configurations
|
|
260
234
|
|
|
261
|
-
|
|
235
|
+
Remote Configurations allow you to proxy existing apis. In the simple example above,
|
|
236
|
+
|
|
237
|
+
```yaml
|
|
238
|
+
# api_dock_config/remotes/service1.yaml
|
|
239
|
+
name: service1
|
|
240
|
+
description: "API Service1"
|
|
241
|
+
url: https://remote.api.com
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
`name` defines the slug and `url` points to the existing api. So any route on `https://remote.api.com/*` may also be reached by at `service1/*`. However, the configuration file offers much more control over what endpoints may or may not be served through the api-proxy. In particular, specific endpoints may be added or blocked, methods such as `DELETE` may be blocked, and routes with different signatures may be parsed. The structure is as follows:
|
|
262
245
|
|
|
263
246
|
```yaml
|
|
264
247
|
# api_dock_config/remotes/service1.yaml
|
|
265
|
-
name:
|
|
266
|
-
url:
|
|
267
|
-
description:
|
|
248
|
+
name: # <str> this is the slug that goes in the url
|
|
249
|
+
url: # <str> the base-url of the api being proxied
|
|
250
|
+
description: # (optional) <str> included in response for /service1 base route
|
|
268
251
|
|
|
269
|
-
#
|
|
270
|
-
|
|
271
|
-
#
|
|
272
|
-
- health # GET http://api.example.com/health
|
|
273
|
-
- route: users # GET http://api.example.com/users (using explicit method)
|
|
274
|
-
method: get
|
|
275
|
-
- users/{{user_id}} # GET http://api.example.com/users/{{user_id}}
|
|
276
|
-
- route: users/{{user_id}}/posts # POST http://api.example.com/users/{{user_id}}/posts
|
|
277
|
-
method: post
|
|
278
|
-
# route with a different signature
|
|
279
|
-
- route: users/{{user_id}}/permissions # GET http://api.example.com/user-permissions/{{user_id}}
|
|
280
|
-
remote_route: user-permissions/{{user_id}}
|
|
281
|
-
method: get
|
|
252
|
+
routes: # (optional) <list[str, dict]> constrain available-routes or map between route-signatures
|
|
253
|
+
|
|
254
|
+
restricted: # (optional) <list[str, dict]> block specific endpoints or methods
|
|
282
255
|
```
|
|
283
256
|
|
|
284
257
|
### Variable Placeholders
|
|
@@ -290,7 +263,9 @@ Routes use double curly braces `{{}}` for variable placeholders:
|
|
|
290
263
|
- `users/{{user_id}}/profile` - Matches "users/123/profile"
|
|
291
264
|
- `{{}}` - Anonymous variable (matches any single path segment)
|
|
292
265
|
|
|
293
|
-
###
|
|
266
|
+
### Routes
|
|
267
|
+
|
|
268
|
+
#### String Routes (Simple GET Routes)
|
|
294
269
|
|
|
295
270
|
```yaml
|
|
296
271
|
routes:
|
|
@@ -300,7 +275,7 @@ routes:
|
|
|
300
275
|
- posts/{{post_id}} # GET /posts/456
|
|
301
276
|
```
|
|
302
277
|
|
|
303
|
-
|
|
278
|
+
#### Dictionary Routes (Custom Methods and Mappings)
|
|
304
279
|
|
|
305
280
|
```yaml
|
|
306
281
|
routes:
|
|
@@ -327,20 +302,18 @@ routes:
|
|
|
327
302
|
|
|
328
303
|
You can restrict access to specific routes using the `restricted` section. Restrictions support wildcards and method-specific filtering:
|
|
329
304
|
|
|
330
|
-
|
|
331
|
-
name: restricted_config
|
|
332
|
-
|
|
333
|
-
...
|
|
334
|
-
|
|
335
|
-
routes:
|
|
336
|
-
...
|
|
305
|
+
#### String Routes Restrictions
|
|
337
306
|
|
|
307
|
+
```yaml
|
|
338
308
|
# Simple route restrictions (string format)
|
|
339
309
|
restricted:
|
|
340
310
|
- admin/{{}} # Block all admin routes (single segment wildcard)
|
|
341
311
|
- users/{{user_id}}/private # Block private user data
|
|
342
312
|
- system/* # Block all routes starting with system/ (prefix wildcard)
|
|
313
|
+
```
|
|
343
314
|
|
|
315
|
+
#### Dictionary Routes Restrictions
|
|
316
|
+
```yaml
|
|
344
317
|
# Method-aware restrictions (dict format)
|
|
345
318
|
restricted:
|
|
346
319
|
- route: "*"
|
|
@@ -351,25 +324,27 @@ restricted:
|
|
|
351
324
|
method: patch # Block PATCH requests to user routes
|
|
352
325
|
```
|
|
353
326
|
|
|
354
|
-
**Wildcard Patterns:**
|
|
355
|
-
- `{{}}` or `*` - Matches any single path segment (e.g., `users/{{}}` matches `users/123`)
|
|
356
|
-
- `prefix/*` - Matches all routes starting with prefix/ (e.g., `admin/*` matches `admin/dashboard`, `admin/users/123`, etc.)
|
|
357
|
-
- `*` - When used alone (string format), matches any single-segment route
|
|
358
|
-
- `{route: "*", method: "X"}` - When used with a method (dict format), matches ALL routes regardless of path length
|
|
359
|
-
|
|
360
|
-
**Method-Specific Restrictions:**
|
|
361
|
-
- Use dict format with `route` and `method` fields to restrict specific HTTP methods
|
|
362
|
-
- When `{route: "*", method: "X"}` is used, it blocks the specified method on ALL routes
|
|
363
|
-
- Omit `method` field to restrict all methods for a route
|
|
364
|
-
- Methods are case-insensitive (DELETE, delete, Delete all work)
|
|
365
|
-
|
|
366
|
-
**For more details**, see the [Routing and Restrictions Wiki](https://github.com/yourusername/api_dock/wiki/Routing-and-Restrictions).
|
|
367
327
|
|
|
368
328
|
---
|
|
369
329
|
|
|
370
330
|
## SQL Database Support
|
|
371
331
|
|
|
372
|
-
|
|
332
|
+
Adding databases is similar to adding remote-apis, however now the `routes` section is required and maps directly to specifc `SQL` queries. Database routes support declarative URL query parameters via the `query_params` section. This lets you add filtering, sorting, pagination, conditional logic, and direct responses — all driven by the URL query string. Here's the structure
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
```yaml
|
|
336
|
+
# api_dock_config/databases/versioned_db/0.1.yaml
|
|
337
|
+
name: # <str> this is the slug that goes in the url
|
|
338
|
+
description: # (optional) <str> included in response for /versioned_db/0.1 base route
|
|
339
|
+
authors: # (optional) <str,list> included in response for /versioned_db/0.1 base route
|
|
340
|
+
|
|
341
|
+
tables: # <list[dict(name: uri)]> table definitions
|
|
342
|
+
queries: # (optional) named-queries used for complex sql queries for readability
|
|
343
|
+
|
|
344
|
+
routes: # <list[dict]> maps routes to sql queries
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
For now only parquet support is working but we will be adding other Databases in the future.
|
|
373
348
|
|
|
374
349
|
|
|
375
350
|
### Database Configuration
|
|
@@ -414,7 +389,7 @@ queries:
|
|
|
414
389
|
|
|
415
390
|
routes:
|
|
416
391
|
- route: users/{{user_id}}/permissions
|
|
417
|
-
sql: "[[
|
|
392
|
+
sql: "[[get_user_permissions]]"
|
|
418
393
|
```
|
|
419
394
|
|
|
420
395
|
|
|
@@ -455,15 +430,12 @@ routes:
|
|
|
455
430
|
sql: "[[get_permissions]]"
|
|
456
431
|
```
|
|
457
432
|
|
|
458
|
-
**For more details**, see the [SQL Database Support Wiki](https://github.com/
|
|
433
|
+
**For more details**, see the [SQL Database Support Wiki](https://github.com/SchmidtDSE/api_dock/wiki/SQL-Database-Support).
|
|
459
434
|
|
|
460
435
|
---
|
|
461
436
|
|
|
462
437
|
## URL Query Parameters
|
|
463
438
|
|
|
464
|
-
Database routes support declarative URL query parameters via the `query_params` section. This lets you add filtering, sorting, pagination, conditional logic, and direct responses — all driven by the URL query string.
|
|
465
|
-
|
|
466
|
-
Routes without a `query_params` section work exactly as before (full backward compatibility).
|
|
467
439
|
|
|
468
440
|
### Basic Filtering with `sql`
|
|
469
441
|
|
|
@@ -667,6 +639,63 @@ Parameters are processed in this order (first match wins for early returns):
|
|
|
667
639
|
5. `sql_append` parameters — append post-WHERE clauses (ORDER BY, LIMIT, etc.)
|
|
668
640
|
6. Execute final SQL query
|
|
669
641
|
|
|
642
|
+
---
|
|
643
|
+
|
|
644
|
+
# CLI
|
|
645
|
+
|
|
646
|
+
## Commands
|
|
647
|
+
|
|
648
|
+
API Dock provides a modern Click-based CLI:
|
|
649
|
+
|
|
650
|
+
- **pixi run api-dock** (default): List all available configurations and commands
|
|
651
|
+
- **pixi run api-dock init [--force]**: Initialize `api_dock_config/` directory with default configs
|
|
652
|
+
- **pixi run api-dock start [config_name]**: Start API Dock server with optional config name
|
|
653
|
+
- **pixi run api-dock describe [config_name]**: Display formatted configuration with expanded SQL queries
|
|
654
|
+
- **pixi run api-dock encrypt <plaintext>**: Encrypt values using local/AWS KMS encryption
|
|
655
|
+
- **pixi run api-dock decrypt <ciphertext>**: Decrypt encrypted values (for testing/debugging)
|
|
656
|
+
- **pixi run api-dock generate-key**: Generate new Fernet encryption key for local encryption
|
|
657
|
+
|
|
658
|
+
**Note**: All commands shown use `pixi run` for the pixi environment. If not using pixi, drop the `pixi run` prefix (e.g., `api-dock start` instead of `pixi run api-dock start`).
|
|
659
|
+
|
|
660
|
+
|
|
661
|
+
## Examples
|
|
662
|
+
|
|
663
|
+
```bash
|
|
664
|
+
# Initialize local configuration directory
|
|
665
|
+
pixi run api-dock init
|
|
666
|
+
|
|
667
|
+
# List available configurations, and available commands
|
|
668
|
+
pixi run api-dock
|
|
669
|
+
|
|
670
|
+
# Start API server
|
|
671
|
+
# - default configuration (api_dock_config/config.yaml) with FastAPI
|
|
672
|
+
pixi run api-dock start
|
|
673
|
+
# - default configuration with Flask (backbone options: fastapi (default) or flask)
|
|
674
|
+
pixi run api-dock start --backbone flask
|
|
675
|
+
# - specify with host and/or port
|
|
676
|
+
pixi run api-dock start --host 0.0.0.0 --port 9000
|
|
677
|
+
|
|
678
|
+
# Alternative configurations (example: api_dock_config/config_v2.yaml)
|
|
679
|
+
pixi run api-dock start config_v2
|
|
680
|
+
pixi run api-dock describe config_v2
|
|
681
|
+
|
|
682
|
+
# Encryption commands
|
|
683
|
+
pixi run api-dock generate-key # Generate new encryption key
|
|
684
|
+
pixi run api-dock encrypt "my-secret-token" # Encrypt using local key
|
|
685
|
+
pixi run api-dock encrypt --method aws_kms --key-id arn:aws:... "secret" # Encrypt using AWS KMS
|
|
686
|
+
pixi run api-dock decrypt "gAAAAABh..." # Decrypt encrypted value
|
|
687
|
+
```
|
|
688
|
+
|
|
689
|
+
**For more details**, see the [Configuration Wiki](https://github.com/SchmidtDSE/api_dock/wiki/Configuration).
|
|
690
|
+
|
|
691
|
+
---
|
|
692
|
+
|
|
693
|
+
|
|
694
|
+
|
|
695
|
+
|
|
696
|
+
|
|
697
|
+
---
|
|
698
|
+
|
|
670
699
|
# Cookies and Authentication
|
|
671
700
|
|
|
672
701
|
API Dock supports cookie extraction and authentication for both remote APIs and database routes. Cookies can be passed through to remote APIs or used for authentication validation.
|
|
@@ -762,7 +791,7 @@ authentication:
|
|
|
762
791
|
|
|
763
792
|
- `encrypted: true/false` - Whether stored values are encrypted and need decryption
|
|
764
793
|
|
|
765
|
-
Note: Authentication
|
|
794
|
+
Note: Authentication extracts tokens from cookies and supports multiple backend sources including AWS Secrets Manager, AWS KMS encryption, GCP Secret Manager, and file-based authentication.
|
|
766
795
|
|
|
767
796
|
For detailed setup instructions and examples, see the complete authentication documentation.
|
|
768
797
|
|
|
@@ -775,7 +804,7 @@ The core functionality is available as a standalone `RouteMapper` class that can
|
|
|
775
804
|
## Basic Integration
|
|
776
805
|
|
|
777
806
|
```python
|
|
778
|
-
from api_dock
|
|
807
|
+
from api_dock import RouteMapper
|
|
779
808
|
import asyncio
|
|
780
809
|
|
|
781
810
|
# Initialize with optional config path
|
|
@@ -863,7 +892,9 @@ route_mapper = RouteMapper(config_path="path/to/config.yaml")
|
|
|
863
892
|
async def query_database():
|
|
864
893
|
success, data, status, error = await route_mapper.map_database_route(
|
|
865
894
|
database_name="db_example",
|
|
866
|
-
path="users/123"
|
|
895
|
+
path="users/123",
|
|
896
|
+
query_params={},
|
|
897
|
+
cookies={}
|
|
867
898
|
)
|
|
868
899
|
|
|
869
900
|
if success:
|
|
@@ -928,7 +959,7 @@ def database_proxy(database_name, path):
|
|
|
928
959
|
|
|
929
960
|
# Advanced Configuration Examples
|
|
930
961
|
|
|
931
|
-
This section provides examples for advanced API Dock features mentioned in the [
|
|
962
|
+
This section provides examples for advanced API Dock features mentioned in the [Simple Example](#simple-example).
|
|
932
963
|
|
|
933
964
|
## Route Restrictions
|
|
934
965
|
|
|
@@ -1088,26 +1119,6 @@ pixi run jupyter lab .
|
|
|
1088
1119
|
pixi run python scripts/hello_world.py
|
|
1089
1120
|
```
|
|
1090
1121
|
|
|
1091
|
-
The first time `pixi run` is executed the project will be installed (note this means the first run will be a bit slower). Any changes to the project will be updated on the subsequent `pixi run`. It is unnecessary, but you can run `pixi install` after changes - this will update your local environment, so that it does not need to be updated on the next `pixi run`.
|
|
1092
|
-
|
|
1093
|
-
Note, the repo's `pyproject.toml`, and `pixi.lock` files ensure `pixi run` will just work. No need to recreate an environment. Additionally, the `pyproject.toml` file includes `api_dock = { path = ".", editable = true }`. This line is equivalent to `pip install -e .`, so there is no need to pip install this module.
|
|
1094
|
-
|
|
1095
|
-
The project was initially created using a `package_names.txt` and the following steps. Note that this should **NOT** be re-run as it will create a new project (potentially changing package versions).
|
|
1096
|
-
|
|
1097
|
-
```bash
|
|
1098
|
-
#
|
|
1099
|
-
# IMPORTANT: Do NOT run this unless you explicity want to create a new pixi project
|
|
1100
|
-
#
|
|
1101
|
-
# 1. initialize pixi project (in this case the pyproject.toml file had already existed)
|
|
1102
|
-
pixi init . --format pyproject
|
|
1103
|
-
# 2. add specified python version
|
|
1104
|
-
pixi add python=3.11
|
|
1105
|
-
# 3. add packages (note this will use pixi magic to determine/fix package version ranges)
|
|
1106
|
-
pixi add $(cat package_names.txt)
|
|
1107
|
-
# 4. add pypi-packages, if any (note this will use pixi magic to determine/fix package version ranges)
|
|
1108
|
-
pixi add --pypi $(cat pypi_package_names.txt)
|
|
1109
|
-
```
|
|
1110
|
-
|
|
1111
1122
|
---
|
|
1112
1123
|
|
|
1113
1124
|
# License
|