API Call
In Launchfa.st, to make it more easier for the developers, all the APIs are right now inside the
src/pages/api
directory. In Launchfa.st, to make it more easier for the developers, all the APIs are right now inside the
src/routes/api
directory. Any file inside the src/pages
ending with .js
/.ts
can be an API enpoint.
The good thing with APIs with Launchfa.st is that you get to use the Web APIs on top of Astro. This ensures that the code can be reused in any number of projects irresepctive of their stack.
Find more on the API Routes in Astro at https://docs.astro.build/en/core-concepts/endpoints.
Any file inside the src/routes
ending with +server.ts
can be an API enpoint.
Find more on the API Routes in SvelteKit at https://kit.svelte.dev/docs/routing#server.
Protected API Routes
To illustrate, to create an API route that returns whether a user is logged in or not, follow the steps in the LaunchFa.st template:
- Create a file:
src/pages/api/test.js
. - Add the content below to the
test.js
:
- Create a file:
src/route/api/test/+server.ts
. - Add the content below to the
+server.ts
: