Skip to content

Commit f1446c6

Browse files
author
Olivier Auverlot
committed
Changes for the shell-empty documentation
1 parent 1265b5f commit f1446c6

File tree

1 file changed

+28
-12
lines changed

1 file changed

+28
-12
lines changed

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

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1525,22 +1525,38 @@ SELECT
15251525
SQLPage provides the `shell-empty` component to create a page without a shell.
15261526
In this case, the `html` and `body` tags are not generated, and the components are rendered directly in the page
15271527
without any styling, navigation bar, footer, or dynamic content.
1528-
This is useful when you want to generate a snippet of HTML that can be dynamically included in a larger page.
1529-
15301528
Any component whose name starts with `shell` will be considered as a shell component,
15311529
so you can also [create your own shell component](custom_components.sql#custom-shell).
15321530
1531+
This is particularly useful when creating a [RESTful API](https://en.wikipedia.org/wiki/REST) with SQLPage.
1532+
Typically, the data returned to the client is not formatted in HTML but rather in JSON or XML.
1533+
With the `shell-empty` component, you simply need to construct the formatted data and assign it to the contents property.
1534+
1535+
Remember to use the [http_header](component.sql?component=http%5Fheader) component beforehand to inform the client about the format of the data being sent.
1536+
1537+
In the example below, SQLPage returns data formatted in XML.
1538+
The correct [MIME](https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/MIME_types/Common_types) type should be `application/xml`.
1539+
',
1540+
json('[
1541+
{
1542+
"component":"http_header",
1543+
"Content-Type":"application/xml"
1544+
},
1545+
{
1546+
"component":"shell-empty",
1547+
"contents": "<?xml version=\"1.0\"?>\n <user>\n <account>42</account>\n <login>john.doe</login>\n </user>"
1548+
}
1549+
]')
1550+
),
1551+
('shell','
1552+
### Generate your own HTML
15331553
If you generate your own HTML from a SQL query, you can also use the `shell-empty` component to include it in a page.
1554+
This is useful when you want to generate a snippet of HTML that can be dynamically included in a larger page.
15341555
Make sure you know what you are doing, and be careful to escape the HTML properly,
1535-
as you are stepping out of the safe SQLPage framework and into the wild world of HTML.',
1536-
json('[{"component":"shell-empty", "html": "<!DOCTYPE html>\n<html>\n<head>\n <title>My page</title>\n</head>\n<body>\n <h1>My page</h1>\n</body>\n</html>"}]')),
1537-
('shell','
1538-
### Return data in a format other than HTML
1539-
If you create a RESTful API with SQLPage and the data format transmitted to the client is not HTML,
1540-
you can use an alias named `contents` to enhance the readability of your code.
1541-
This approach is particularly useful for returning data formats such as JSON or XML.
1556+
as you are stepping out of the safe SQLPage framework and into the wild world of HTML.
15421557
1543-
Remember to use the [http_header](component.sql?component=http%5Fheader) component beforehand to inform the client about the format of the data being sent.
1544-
For example, for XML, the correct [MIME](https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/MIME_types/Common_types) type should be `application/xml`.
1558+
In this scenario, you can use the `html` property, which serves as an alias for the `contents` property.
1559+
This property improves code readability by clearly indicating that you are generating HTML.
1560+
Since SQLPage returns HTML by default, there is no need to specify the content type in the HTTP header.
15451561
',
1546-
json('[{"component":"shell-empty", "contents": "<?xml version=\"1.0\"?>\n <user>\n <account>42</account>\n <login>john.doe</login>\n </user>"}]'));
1562+
json('[{"component":"shell-empty", "html": "<!DOCTYPE html>\n<html>\n<head>\n <title>My page</title>\n</head>\n<body>\n <h1>My page</h1>\n</body>\n</html>"}]'));

0 commit comments

Comments
 (0)