"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 = () => {\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 = () => {\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 ",