You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Support JSON responses via Accept header
* no update in migrations
* No UPDATE in official site migrations
- Updated the JSON component description to clarify its integration with external services and the ability to serve both HTML and JSON based on the HTTP Accept header.
- Added examples demonstrating how to request JSON responses using `curl`.
- Removed the obsolete migration file that documented the JSON response format feature, consolidating information into the main documentation.
* revert stupid docs example change
stupid bot
* simplify tests
* avoid string then json in tests, parse as json directly
* changelog
Copy file name to clipboardExpand all lines: AGENTS.md
+9-5Lines changed: 9 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -28,15 +28,19 @@ docker compose up -d mssql # or postgres or mysql
28
28
DATABASE_URL='mssql://root:Password123!@localhost/sqlpage' cargo test # all dbms use the same user:pass and db name
29
29
```
30
30
31
+
### Documentation
32
+
33
+
Components and functions are documented in [official website](./examples/official-site/sqlpage/migrations/); one migration per component and per function. You CAN update existing migrations, the official site database is recreated from scratch on each deployment.
34
+
35
+
official documentation website sql tables:
36
+
-`component(name,description,icon,introduced_in_version)` -- icon name from tabler icon
- Components: defined in `./sqlpage/templates/*.handlebars`
34
43
- Functions: `src/webserver/database/sqlpage_functions/functions.rs` registered with `make_function!`.
35
-
- Components and functions are documented in [official website](./examples/official-site/sqlpage/migrations/); one migration per component and per function.
36
-
- tables
37
-
-`component(name,description,icon,introduced_in_version)` -- icon name from tabler icon
Copy file name to clipboardExpand all lines: CHANGELOG.md
+3Lines changed: 3 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,9 @@
1
1
# CHANGELOG.md
2
2
3
3
## 0.40.0 (unreleased)
4
+
- SQLPage now respects [HTTP accept headers](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Accept) for JSON. You can now easily process the contents of any existing sql page programmatically with:
5
+
-`curl -H "Accept: application/json" http://example.com/page.sql`: returns a json array
6
+
-`curl -H "Accept: application/x-ndjson" http://example.com/page.sql`: returns one json object per line.
4
7
- Fixed a bug in `sqlpage.link`: a link with no path (link to the current page) and no url parameter now works as expected. It used to keep the existing url parameters instead of removing them. `sqlpage.link('', '{}')` now returns `'?'` instead of the empty string.
Copy file name to clipboardExpand all lines: examples/official-site/sqlpage/migrations/11_json.sql
+10Lines changed: 10 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -18,6 +18,10 @@ This component **must appear at the top of your SQL file**, before any other dat
18
18
An HTTP response can have only a single datatype, and it must be declared in the headers.
19
19
So if you have already called the `shell` component, or another traditional HTML component,
20
20
you cannot use this component in the same file.
21
+
22
+
SQLPage can also return JSON or JSON Lines when the incoming request says it prefers them with an HTTP `Accept` header, so the same `/users.sql` page can show a table in a browser but return raw data to `curl -H "Accept: application/json" http://localhost:8080/users.sql`.
23
+
24
+
Use this component when you want to control the payload or force JSON output even for requests that would normally get HTML.
21
25
',
22
26
'code',
23
27
'0.9.0'
@@ -84,6 +88,12 @@ select * from users;
84
88
{"username":"James","userid":1},
85
89
{"username":"John","userid":2}
86
90
]
91
+
```
92
+
93
+
Clients can also receive JSON or JSON Lines automatically by requesting the same SQL file with an HTTP `Accept` header such as `application/json` or `application/x-ndjson` when the component is omitted, for example:
0 commit comments