oliverdavies.uk/content/node.1c19d543-604f-43e8-bdaa-c7d3df15d4be.json
2025-05-11 20:02:14 +01:00

100 lines
No EOL
5 KiB
JSON

{
"uuid": [
{
"value": "1c19d543-604f-43e8-bdaa-c7d3df15d4be"
}
],
"langcode": [
{
"value": "en"
}
],
"type": [
{
"target_id": "daily_email",
"target_type": "node_type",
"target_uuid": "8bde1f2f-eef9-4f2d-ae9c-96921f8193d7"
}
],
"revision_timestamp": [
{
"value": "2025-05-11T06:09:49+00:00"
}
],
"revision_uid": [
{
"target_type": "user",
"target_uuid": "b8966985-d4b2-42a7-a319-2e94ccfbb849"
}
],
"revision_log": [],
"status": [
{
"value": true
}
],
"uid": [
{
"target_type": "user",
"target_uuid": "b8966985-d4b2-42a7-a319-2e94ccfbb849"
}
],
"title": [
{
"value": "Creating API endpoints with Astro\n"
}
],
"created": [
{
"value": "2023-02-09T00:00:00+00:00"
}
],
"changed": [
{
"value": "2025-05-11T06:09:49+00:00"
}
],
"promote": [
{
"value": false
}
],
"sticky": [
{
"value": false
}
],
"default_langcode": [
{
"value": true
}
],
"revision_translation_affected": [
{
"value": true
}
],
"path": [
{
"alias": "\/daily\/2023\/02\/09\/creating-api-endpoints-with-astro",
"langcode": "en"
}
],
"body": [
{
"value": "\n <p>As well as <a href=\"https:\/\/www.oliverdavies.uk\/daily\/2023\/02\/08\/fetching-api-data-with-astro\">fetching API data<\/a>, you can also use Astro to generate your own API endpoints.<\/p>\n\n<p>This is an example of an endpoint that I recently created as part of a demo application:<\/p>\n\n<pre><code class=\"javascript\">\/\/ trains.json.ts\n\nimport data from \"@\/data.json\";\nimport type { APIRoute } from \"astro\";\nimport type { Train } from \"@\/types\";\n\nexport const get: APIRoute = () =&gt; {\n return {\n body: JSON.stringify(data.trains as Train[]),\n };\n};\n<\/code><\/pre>\n\n<p>The train data is imported from a JSON file, and Astro's <code>APIRoute<\/code> is responsible for setting the appropriate response headers.<\/p>\n\n<p>For server-side rendered applications, you can also have endpoints for <code>post<\/code>, <code>del<\/code> and <code>all<\/code>, though for this example, I only needed to support GET requests.<\/p>\n\n<p>This is something that I've used a db-json library for previously, but being able to do this in Astro seemed like a good fit as I can easily manage lists of stations as well as a single station from one JSON file but I can just take the static HTML that Astro generates and upload it to a static hosting solution which simplifies the hosting side of things a lot.<\/p>\n\n<p>And, as the example application that consumes the data is also written with Astro, having them both using the same solution has advantages too.<\/p>\n\n ",
"format": "full_html",
"processed": "\n <p>As well as <a href=\"https:\/\/www.oliverdavies.uk\/daily\/2023\/02\/08\/fetching-api-data-with-astro\">fetching API data<\/a>, you can also use Astro to generate your own API endpoints.<\/p>\n\n<p>This is an example of an endpoint that I recently created as part of a demo application:<\/p>\n\n<pre><code class=\"javascript\">\/\/ trains.json.ts\n\nimport data from \"@\/data.json\";\nimport type { APIRoute } from \"astro\";\nimport type { Train } from \"@\/types\";\n\nexport const get: APIRoute = () =&gt; {\n return {\n body: JSON.stringify(data.trains as Train[]),\n };\n};\n<\/code><\/pre>\n\n<p>The train data is imported from a JSON file, and Astro's <code>APIRoute<\/code> is responsible for setting the appropriate response headers.<\/p>\n\n<p>For server-side rendered applications, you can also have endpoints for <code>post<\/code>, <code>del<\/code> and <code>all<\/code>, though for this example, I only needed to support GET requests.<\/p>\n\n<p>This is something that I've used a db-json library for previously, but being able to do this in Astro seemed like a good fit as I can easily manage lists of stations as well as a single station from one JSON file but I can just take the static HTML that Astro generates and upload it to a static hosting solution which simplifies the hosting side of things a lot.<\/p>\n\n<p>And, as the example application that consumes the data is also written with Astro, having them both using the same solution has advantages too.<\/p>\n\n ",
"summary": null
}
],
"feeds_item": [
{
"imported": "2025-05-11T06:09:49+00:00",
"guid": null,
"hash": "c6a3315ecb8173fc096250981c691fbe",
"target_type": "feeds_feed",
"target_uuid": "90c85284-7ca8-4074-9178-97ff8384fe76"
}
]
}