How to create an API endpoint similar to Nuxt/Nextjs in Svelte routes.
Create a route of your choice (folder 📂) and add a index.json.js which implement and return body.
//index.json.js
export async function get() {
.... boring fetching code 😔 goes here
return {
body: { }
}
}
That is all need to setup an internal API end point.
We can implement our own REST api. Also note that need not use API folder, all its mater is the get function.
- Configure aliases in Svelte Kit
- Passing data among components in Svelte
- Dynamic route in new Svelte Kit
- Static files in Svelte Kit
- Getting current url in Svelte Kit
- Navigate to another route in Svelte Kit (client side)
- Keystroke handling in Svelte
- $lib in Svelte Kit
- How to load data in Svelte Kit routes
- Create Svelte reusable component