Skip to content

Commit d832027

Browse files
committed
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.
1 parent 6091680 commit d832027

File tree

3 files changed

+11
-131
lines changed

3 files changed

+11
-131
lines changed

examples/official-site/sqlpage/migrations/01_documentation.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -893,7 +893,7 @@ Numbers can be displayed
893893
},
894894
{
895895
"feature": "APIs",
896-
"description": "Allows building JSON REST APIs and integrating with external APIs.",
896+
"description": "Allows building JSON REST APIs, integrates with external services, and can serve the same page as HTML in a browser or as JSON to tools like `curl -H \"Accept: application/json\" http://localhost:8080/users.sql`.",
897897
"benefits": "Enables automation and integration with other platforms, facilitates data exchange."
898898
},
899899
{

examples/official-site/sqlpage/migrations/11_json.sql

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ This component **must appear at the top of your SQL file**, before any other dat
1818
An HTTP response can have only a single datatype, and it must be declared in the headers.
1919
So if you have already called the `shell` component, or another traditional HTML component,
2020
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.
2125
',
2226
'code',
2327
'0.9.0'
@@ -84,6 +88,12 @@ select * from users;
8488
{"username":"James","userid":1},
8589
{"username":"John","userid":2}
8690
]
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:
94+
95+
```
96+
curl -H "Accept: application/json" http://localhost:8080/users.sql
8797
```
8898
'
8999
),

examples/official-site/sqlpage/migrations/73_accept_json.sql

Lines changed: 0 additions & 130 deletions
This file was deleted.

0 commit comments

Comments
 (0)